0

I'm trying to insert images to each one of my blog posts using SQLite with Sequel and Sinatra.

DB.create_table :posts do
primary_key :id
String :title
String :content
Datetime :created_at
Datetime :updated_at
foreign_key(:user_id, :users, :type=>String)
end

What changes should I make to my db for that and how can insert the image from the view and later display it?

Any help or idea is highly appreciated.

uklp
  • 551
  • 1
  • 6
  • 14
  • 1
    So, it looks to me, that you are a beginner. Let me ask you a question. Why are you using sequel and sinatra, when there is rails, which is so much better suited for beginners, because there are tons of resources and gems helping you with that. For fileupload, there is dragonfly, paperclip and many more. – phoet Dec 13 '13 at 08:57
  • Yeah, I am, and I was advised to start on Sinatra first. I've done pretty much with these now and I want to keep up as long as I finish this blog so I can switch to Rails afterwards. Any chance you could give me a hand on this? – uklp Dec 13 '13 at 11:31
  • 2
    I would start with the uploading part like this: http://stackoverflow.com/questions/2686044/file-upload-with-sinatra and if you finished that part, I would have a look at how to best store that file in the database (which is not very nice performance wise) – phoet Dec 13 '13 at 14:39

1 Answers1

0

Personally, if it's for a blog then I'd upload the file somewhere - whether that be a filesharing site (your Dropbox or something), and then write an img link to it in the article's text. Why complicate things?

Edit: I'm not suggesting embedding HTML in your document, but (such as in Markdown) an indicator that is then further processed into HTML later, much as the rest of the document will.

I'd also rename Post to Article, since POST is an HTTP verb and used in Sinatra, or else you end up with stuff like this:

post "/post" do
  post = Post.new title: "First Post"
ian
  • 12,003
  • 9
  • 51
  • 107
  • Your idea seems reasonable, I did not down vote it, and I did not try it yet, I was stuck with some other things, but I will give it a shot though. But, I still want to find a more suitable solution, probably connected to my ORM and DB. – uklp Dec 25 '13 at 02:58
  • @uklp don't worry, I wasn't saying you'd voted me down, but someone did! No bother about the wait, it's easy to get stuck on other things… c'est la vie :) – ian Dec 25 '13 at 03:36