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 %>
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Hello, Could You post what is generated by the form? Paperclip is enough smart with mass saving and when he has params[:model][:image] poiting to Your file through file_field :image it should just grab the file (from Rack TMP) and save it as a image. Best, Martin On Mar 30, 7:15 pm, ES <emsto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 %>-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
this is what is generated by the form. I separated the lines at
''Image 1'' which is the value I entered in for the Image
description
but it shows NULL for the image attributes (image_file_name, etc)
Processing AnalysesController#create (for 127.0.0.1 at 2010-03-31
09:26:53) [POST]
Parameters: {"authenticity_token"=>"WuQMc
+ntdX84NSUnXwRbjCXqdSQ0AMAK6VrsxUvv5kQ=",
"analysis"=>{"author"=>"Author 1",
"photo_attributes"=>[{"description"=>"Image
1",
"image"=>"IMG_3132.JPG"},
{"description"=>"", "image"=>""},
{"description"=>"",
"image"=>""}]},
"commit"=>"Create"}
Analysis Columns (2.3ms) SHOW FIELDS FROM `analyses`
Photo Columns (1.6ms) SHOW FIELDS FROM `photos`
SQL (0.2ms) BEGIN
Analysis Create (0.7ms) INSERT INTO `analyses` (`problematik`,
`comment`, `technique`, `samplenbr`, `ref`, `worknbr`, `date`,
`author`, `record`, `created_at`, `updated_at`, `images`) VALUES(NULL,
NULL, NULL, '''', '''', '''',
NULL, ''Author 1'', 0, ''2010-03-31 07:26:53'',
''2010-03-31 07:26:53'', NULL)
Photo Create (0.4ms) INSERT INTO `photos` (`description`,
`author`, `created_at`, `updated_at`, `image_file_name`,
`image_content_type`, `image_file_size`, `image_updated_at`,
`analysis_id`) VALUES
(''Image 1'',
NULL, ''2010-03-31 07:26:53'', ''2010-03-31
07:26:53'', NULL, NULL, NULL,
NULL, 14)
On Mar 31, 9:03 am, Marcin Seroczynski
<sere...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hello,
>
> Could You post what is generated by the form?
>
> Paperclip is enough smart with mass saving and when he has
> params[:model][:image] poiting to Your file through file_field :image
> it should just grab the file (from Rack TMP) and save it as a image.
>
> Best,
> Martin
>
> On Mar 30, 7:15 pm, ES
<emsto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 %>
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
It should work but I would recommend using accepts_nested_attributes_for :image. Few screencasts: http://railscasts.com/episodes/196-nested-model-form-part-1 http://railscasts.com/episodes/197-nested-model-form-part-2 Best, Martin On Mar 31, 5:22 pm, Jeremy Woertink <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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 viahttp://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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.