form tag multipart

Hi to all,

i'm trying to pass the id of my record within the multipart form. I've tried to pass it like this but it gives a compile error....

<%= form_tag( { :action => 'create', :id => @nominee }, :multipart => true ) do -%>   <%= render :partial => 'form' %>   <%= submit_tag 'Edit' %> <% end %>

<%= link_to 'Show', :action => 'show', :id => @nominee %> | <%= link_to 'Back', :action => 'list' %>

Can anybody help me???

Thanks i advance

Andrea

You typically won't pass an id to a create action. I'm doing this with an update action using the same syntax that you have, and it works fine. If it matters, I don't have an equal sign next to my form_tag (i.e., <% form_tag..., not <%= form_tag...).

Do you want to set the id of the record that you're creating (not recommended), or are you trying to pass a value to the record like nominee_id = 12?

If you're still having problems, please paste the error.

-Kyle

Hi Kyle,

sorry :slight_smile: i want to pass it to the update function not the create, but i still have this error:

compile error script/../config/../app/views/nominees/edit.rhtml:4: syntax error, unexpected ')' _erbout.concat(( form_tag( { :action => 'update', :id => @nominee }, :multipart => true ) do ).to_s)

Code

<%= form_tag( { :action => 'update', :id => @nominee }, :multipart => true ) do -%> <%= render :partial => 'form' %> <%= submit_tag 'Edit' %> <% end %>

thanks for your help!!

You'll need

<%= form_tag( { :action => 'update', :id => @nominee }, {:multipart => true} ) do -%>

While Ruby will attempt to do "THE RIGHT THING", you'll find that if
you specify the hash curly-braces on the first hash, you'll also need
to specify them on the second hash.

Julian.

Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO
(#2) OUT NOW! http://sensei.zenunit.com/

While Ruby will attempt to do "THE RIGHT THING", you'll find that if you specify the hash curly-braces on the first hash, you'll also need to specify them on the second hash.

Hi Julian,

i still have an error, the code is:

<h1>Editing nominee</h1>

<%= form_tag( { :action => 'update', :id => @nominee }, {:multipart => true} do) -%> <%= render :partial => 'form' %> <%= submit_tag 'Edit' %> <% end %>

and the compile error:

compile error script/../config/../app/views/nominees/edit.rhtml:4: syntax error, unexpected kDO, expecting ')' _erbout.concat(( form_tag( { :action => 'update', :id => @nominee }, {:multipart => true} do) ).to_s)                                                                                              ^ script/../config/../app/views/nominees/edit.rhtml:5: syntax error, unexpected tIDENTIFIER, expecting ')' _erbout.concat " "; _erbout.concat(( render :partial => 'form' ).to_s); _erbout.concat "\n"        ^ script/../config/../app/views/nominees/edit.rhtml:12: syntax error, unexpected kEND, expecting $end

what could it be?

do has to come after the close parenthesis... do reprsents the start
of a block, and comes after the other arguments, which go inside the
parenthesis.

<%= form_tag( { :action => 'update', :id => @nominee }, {:multipart => true}) do -%> <%= render :partial => 'form' %> <%= submit_tag 'Edit' %> <% end %>

Julian :slight_smile: it doesn't work even like this....

<%= form_tag( { :action => 'update', :id => @nominee }, {:multipart => true}) do -%> <%= render :partial => 'form' %> <%= submit_tag 'Edit' %> <% end %>

the compile error:

compile error script/../config/../app/views/nominees/edit.rhtml:4: syntax error, unexpected ')' _erbout.concat(( form_tag( { :action => 'update', :id => @nominee }, {:multipart => true}) do ).to_s)                                                                                                ^ script/../config/../app/views/nominees/edit.rhtml:14: syntax error, unexpected kEND, expecting ')'

??

Really thanks for your help!

You shouldn't use <%= %> when you're using the block form.

Julian.

Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO
(#2) OUT NOW! http://sensei.zenunit.com/

IT works!!!!!!

Really thanks!!!