Attachment_fu with extra db fields?

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

<%= error_messages_for :image %>
<%= flash[:notice] %>

<% form_for(:image, :url => { :controller => ‘images’, :action =>
‘create’ }, :html => { :multipart => true }) do |f| -%>

Upload An Image: <%= f.file_field :uploaded_data %> <%= hidden_field 'project_id', params[:id] %>

<%= submit_tag 'Create' %>

<% 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:

Upload An Image:

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!

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%>


On May 11, 11:08 am, Lar Van der jagt <rails-mailing-l…@andreas-


The reason is that the name of the form field for the project id is

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])