Forum: Ruby on Rails form_remote_for, reloaded

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F15eda57118c81c7308dbcd904d7ca07?d=identicon&s=25 Andy G. (andor)
on 2007-04-25 21:56
Hi,
being relativly new to RoR, I'm having a problem which I found described
in this forum and somewhere else - but with no solution. I know, that it
may be bad to mix table and form tags, but the first solution of an in
place editing within a table looked nice:

Version using form_for:

<tr>
  <%form_for :time_record, :url => { :action => "add_time_record" } do
|f| %>
    <% f.date_select(:day, :disabled => true, :order => [:day, :month])
%>
    <td><%= f.date_select(:day, :order => [:day, :month]) %></td>
    <td><%= f.collection_select(:user_id, @users, :id, :login_name)
%></td>
    <td><%= f.collection_select(:project_id, @projects, :id, :name)
%></td>
    <td><%= f.text_field :quantity, :size => 4 %></td>
    <td><%= f.text_field :description, :size => 50 %></td>
    <td><%= submit_tag "Zeit Erfassen", :class => "submit" %></td>
  <% end %>
</tr>

Works fine.

Iterating in small steps to AJAX, the next iteration was:

<tr>
  <%form_remote_for :time_record, :url => { :action => "add_time_record"
} do |f| %>
    <% f.date_select(:day, :disabled => true, :order => [:day, :month])
%>
    <td><%= f.date_select(:day, :order => [:day, :month]) %></td>
    <td><%= f.collection_select(:user_id, @users, :id, :login_name)
%></td>
    <td><%= f.collection_select(:project_id, @projects, :id, :name)
%></td>
    <td><%= f.text_field :quantity, :size => 4 %></td>
    <td><%= f.text_field :description, :size => 50 %></td>
    <td><%= submit_tag "Zeit Erfassen" %></td>
  <% end %>
</tr>

Which did not work. Changing the whole thing to

  <tr class="list-line-even">
    <td>
    <%form_remote_for :time_record, :url => { :action =>
"add_time_record" } do |f| %>
      <%= f.date_select(:day, :order => [:day, :month]) %>
      <%= f.collection_select(:user_id, @users, :id, :login_name) %>
      <%= f.collection_select(:project_id, @projects, :id, :name) %>
      <%= f.text_field :quantity, :size => 4 %>
      <%= f.text_field :description, :size => 50 %>
      <%= submit_tag "Zeit Erfassen" %>
    <% end %>
    </td>
  </tr>

works fine again...

Which means mixing of table and form tags destroys the parameter
information.
In my opinion, form_for and form_remote_for should behave the same way.

Hopefully someone has a solution to this problem ?
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2007-04-25 23:11
(Received via mailing list)
Andor Grei├čl wrote:

>     <td><%= f.collection_select(:project_id, @projects, :id, :name)
> %></td>
>     <td><%= f.text_field :quantity, :size => 4 %></td>
>     <td><%= f.text_field :description, :size => 50 %></td>
>     <td><%= submit_tag "Zeit Erfassen" %></td>
>   <% end %>
> </tr>
>
> Which did not work.

This'll work if you instead write something like:

<tr id="time_record">
<% fields_for :time_record do |f| %>
<td><%= f.date_select :day, :disabled => true, :order => [:day, :month]
%></td>
<td><%= f.date_select :day, :order => [:day, :month] %></td>
<td><%= f.collection_select :user_id, @users, :id, :login_name %></td>
<td><%= f.collection_select :project_id, @projects, :id, :name %></td>
<td><%= f.text_field :quantity, :size => 4 %></td>
<td><%= f.text_field :description, :size => 50 %></td>
<td><%= submit_to_remote :commit, "Zeit Erfassen", :submit =>
:time_record,
                          :url => {:action => "add_time_record"} %></td>
<% end %>
</tr>


> In my opinion, form_for and form_remote_for should behave the same way.

They do.  You're lucky your first form_for version worked at all.


--
We develop, watch us RoR, in numbers too big to ignore.
F15eda57118c81c7308dbcd904d7ca07?d=identicon&s=25 Andy G. (andor)
on 2007-04-26 07:45
Thanks for your post - really great. I was just on the wrong way, now it
just works fine.

Best regards,
Andor
This topic is locked and can not be replied to.