开发者

Paperclip with albums

I'm struggling with paperclip and adding the开发者_如何学运维 attached images to albums. Should I be writing an album_id to the images row in the database? Right now, I'm trying to use an album model, which belongs_to :user and has_many :photos. The photo model belongs_to :album and has_attached_file. Is that the way to go about it?

I'm really new to Rails so i'm still getting hung up on things like...

<%= form_for @album, :html => { :mulitpart => true } do |f| %>

because I have no idea how @album is suppose to point to the right controller/action. Another thing is how the h*ll is photo suppose to know which album its apart of? Normally I would have said save the album_id in the photo row but I feel like I'm passing up paperclips functionality.

Rails still hasn't "clicked" for me =/ I think PHP ruined me...or the auto-magickness is too powerful for my mind.


There is no Magic in Rails . It all about how you understand the concepts . In order to understand the rails following things are essential

  1. Basic Knowledge on Ruby

  2. Agile web development will be kick start (Understand MVC Architecture)

  3. Debugging Rails application and script/console

Coming back to your above Paperclip application .

  1. Here @album is an instance variable which holds the value of the form fields like the title ,image etc.

  2. <% form_for(@album,:url => {:controller => "albums" , :action => "create" }) do |f| %> correct syntax is this , which points to the albums controller create action , if you are familiar with the routes you can use new_album_path will also routes as same as above.

  3. h*ll is photo suppose to know which album its apart of? Answer is through specifying Associations in the Model between album and Photo and User. Based on your requirement. set the associations. Associations are the relationship between to two tables , Like in PHP you do foreign key and relate two tables . Best book to learn this is Pro Active Record

  4. Here is a nice tutorial by Jimneath

Hope it helps !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜