I have been working on this problem for two days and can''t seem to make
an progress on it. I am positive that I am just missing something
obvious. I am using attachment_fu, I have created an image model and
images controller, and everything is working fine. Now I want to have
the uploaded images associated with a project using a project_id column.
I want to do this from the show page for each project, grabbing the
project id from the params using a hidden field to pass to the model.
Here is what I put into the show.rhtml view, presented by the projects
controller:
<%= error_messages_for :image %>
<%= flash[:notice] %>
<% form_for(:image, :url => { :controller =>
''images'', :action =>
''create'' }, :html => { :multipart => true }) do |f|
-%>
<p>
<label for="image">Upload An Image:</label>
<%= f.file_field :uploaded_data %>
<%= hidden_field ''project_id'', params[:id] %>
</p>
<p>
<%= submit_tag ''Create'' %>
</p>
<% end -%>
When I submit that it does all the image stuff fine, but does not pass
the project id. When I look at the generated source the project id is
showing up in the form like this:
<form action="/images/create"
enctype="multipart/form-data"
method="post"> <p>
<label for="image">Upload An Image:</label>
<input id="image_uploaded_data"
name="image[uploaded_data]"
size="30" type="file" />
<input id="project_id_1" name="project_id[1]"
type="hidden" />
</p>
<p>
<input name="commit" type="submit"
value="Create" />
</p>
</form>
Am I losing the id in the redirect to the images controller? Can anybody
shed some light on the proper way to do this? I haven''t had any luck
searching around the web. Help is much appreciated!
--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Might want to try hidden_field_tag vs. hidden_field seeing you are not using the f on hidden_field as part of your form. <%=hidden_field_tag :field_name, field_value%> Scott On May 11, 11:08 am, Lar Van der jagt <rails-mailing-l...@andreas- s.net> wrote:> I have been working on this problem for two days and can''t seem to make > an progress on it. I am positive that I am just missing something > obvious. I am using attachment_fu, I have created an image model and > images controller, and everything is working fine. Now I want to have > the uploaded images associated with a project using a project_id column. > I want to do this from the show page for each project, grabbing the > project id from the params using a hidden field to pass to the model. > Here is what I put into the show.rhtml view, presented by the projects > controller: > > <%= error_messages_for :image %> > <%= flash[:notice] %> > > <% form_for(:image, :url => { :controller => ''images'', :action => > ''create'' }, :html => { :multipart => true }) do |f| -%> > <p> > <label for="image">Upload An Image:</label> > <%= f.file_field :uploaded_data %> > <%= hidden_field ''project_id'', params[:id] %> > </p> > <p> > <%= submit_tag ''Create'' %> > </p> > <% end -%> > > When I submit that it does all the image stuff fine, but does not pass > the project id. When I look at the generated source the project id is > showing up in the form like this: > > <form action="/images/create" enctype="multipart/form-data" > method="post"> <p> > <label for="image">Upload An Image:</label> > <input id="image_uploaded_data" name="image[uploaded_data]" > size="30" type="file" /> > <input id="project_id_1" name="project_id[1]" type="hidden" /> > </p> > <p> > <input name="commit" type="submit" value="Create" /> > </p> > > </form> > > Am I losing the id in the redirect to the images controller? Can anybody > shed some light on the proper way to do this? I haven''t had any luck > searching around the web. Help is much appreciated! > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Howdy, The reason is that the name of the form field for the project id is wrong. See how the file upload is image[uploaded_data] ? That is being parsed in the controller into the image object but the project_id is not because of how it is setup. Try this for the hidden field: <%= hidden_field_tag ''image[project_id]'', params[:id] %> I haven''t tried this but you see what I''m getting at... Or, keep your original and then in the controller, something like: image.project = Project.find(params[:project_id]) Hunter On May 11, 2007, at 11:08 AM, Lar Van der jagt wrote:> > I have been working on this problem for two days and can''t seem to > make > an progress on it. I am positive that I am just missing something > obvious. I am using attachment_fu, I have created an image model and > images controller, and everything is working fine. Now I want to have > the uploaded images associated with a project using a project_id > column. > I want to do this from the show page for each project, grabbing the > project id from the params using a hidden field to pass to the model. > Here is what I put into the show.rhtml view, presented by the projects > controller: > > <%= error_messages_for :image %> > <%= flash[:notice] %> > > <% form_for(:image, :url => { :controller => ''images'', :action => > ''create'' }, :html => { :multipart => true }) do |f| -%> > <p> > <label for="image">Upload An Image:</label> > <%= f.file_field :uploaded_data %> > <%= hidden_field ''project_id'', params[:id] %> > </p> > <p> > <%= submit_tag ''Create'' %> > </p> > <% end -%> > > When I submit that it does all the image stuff fine, but does not pass > the project id. When I look at the generated source the project id is > showing up in the form like this: > > <form action="/images/create" enctype="multipart/form-data" > method="post"> <p> > <label for="image">Upload An Image:</label> > <input id="image_uploaded_data" name="image[uploaded_data]" > size="30" type="file" /> > <input id="project_id_1" name="project_id[1]" type="hidden" /> > </p> > <p> > <input name="commit" type="submit" value="Create" /> > </p> > > </form> > > Am I losing the id in the redirect to the images controller? Can > anybody > shed some light on the proper way to do this? I haven''t had any luck > searching around the web. Help is much appreciated! > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---