On Aug 18, 2011, at 2:30 AM, Kapil K. wrote:
you told to me this solution
If you're using Paperclip or CarrierWave, just add two separate file
attributes to your base model, following the usual instructions for
either. If you want to be able to attach N number of files of any
format to a base model, consider the nested_form Gem by Ryan Bates,
and be sure to watch his Railscast on "Complex Forms 1 & 2" to make
sure you grasp what the gem is making for you.
but,i am the fresher please told me how to add two separate file
attributes in our model? kindly give me the solution with small code?
Assuming you are using Paperclip, and you have a Foo model, and you
have read the ReadMe on the Paperclip GitHub page, you would do this:
rails generate paperclip Foo image_one
rails generate paperclip Foo image_two
rake db:migrate
Now you have the proper bits in your database. If you are using
attr_accessible in your model (please say yes) then you have to
add :image_one, :image_two, to the beginning of the list of accessible
attributes.
Add
has_attached_file :image_one, :styles => {}
has_attached_file :image_two, :styles => {}
to your model.
In your view's form_for call, add :html => { :multipart => true }
before the do, so it looks like this:
<%= form_for @foo, :html => { :multipart => true } do |f| %>
In your form body, add a field for each image:
<%= f.file_field :image_one %>
<%= f.file_field :image_two %>
And you're done. Files will upload to your public/system/foos/
image_[one|two]/original/ folder, off the top of my head. You can
configure EVERYTHING, just read the Wiki.
Walter
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google
Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-
t...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com
.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
.
--
You received this message because you are subscribed to the Google Groups "Ruby on
Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.