Forum: Ruby on Rails submit input to params

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
sa 1. (Guest)
on 2009-02-18 14:46
I have a form for a model, that has an auto-fill button based on
existing record. Basically you can choose if to duplicate an existing
record using a select list of the record already in the db.

This select list is inside the form for the new model, but I need to
somehow submit it in an independent manner from the rest of the form. I
was able to do this with observe_field, but I want to do it using a
button or link:

<% form_for @product, :url => { :action => 'create' } do -%>

<%= collection_select :product, :id, Product.find(:all), :id, :name %>
<%= link_to 'fill form', :url => { :action => 'fill_form' } %>

# product fields

<% end %>

I'm having trouble catching the actual selection in the params[], and
I'd really appreciate help on this - thanks.
sa 1. (Guest)
on 2009-02-19 15:23
I used link_to_remote with the :submit option pointing to the parent of
the input I want to submit (doesn't have to be a form!).

<% form_for ... do |f| %>
  <span id="inside_form">
    <%= collection_select ... %>
    <%= link_to_remote... :submit => 'inside_form' %>

  # rest of form fields
<% end %>

Hope this helps someone :)
This topic is locked and can not be replied to.