ES wrote:
> I have an object that has multiple photos uploaded to it, using the
> paperclip plugin. I used a virtual attribute to have mutliple photos
> in the form but I can't figure out how to get the image to save. It
> works if I put <%= photo_form.file_field :image_file_name %> instead
> of just :image. If I use just the following, the image_file_name
> field is blank when it is saved.
>
>
>
> <% for photo in @analysis.photos %>
> <% fields_for "analysis[photo_attributes][]", photo do |photo_form|
> %>
> <p>
> image description: <%= photo_form.text_field :description %>
> <%= photo_form.file_field :image %>
> </p>
> <% end %>
> <% end %>
I know in Rails 2.3.5 there's an easier way to do this, but I cheated a
bit an used attribute_fu because of this cool helper method.
<% form_for :analysis, @analysis, :url => analysis_path, :html => {
:multipart => true } do |analysis_form| %>
<%= analysis_form.render_associated_form(@analysis.photos, :new => 4) %>
<%= analysis_form.submit('Submit') %>
Then you just add a partial called _photo.html.erb inside your analysis
view folder, and throw in
<%= analysis_form.label(:image) %>
<%= analysis_form.file_field(:image) %>
In your model you would put
class Analysis < ActiveRecord::Base
has_many :photos, :attributes => true
end
Hope that helps.
~Jeremy
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.