Form_remote_for, reloaded

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:

<%form_for :time_record, :url => { :action => "add_time_record" } do |f| %> <% f.date_select(:day, :disabled => true, :order => [:day, :month]) %> <%= 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", :class => "submit" %> <% end %>

Works fine.

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

<%form_remote_for :time_record, :url => { :action => "add_time_record" } do |f| %> <% f.date_select(:day, :disabled => true, :order => [:day, :month]) %> <%= 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 %>

Which did not work. Changing the whole thing to

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

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 ?

Andor Greißl wrote:

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

Which did not work.

This’ll work if you instead write something like:

<% fields_for :time_record do |f| %> <%= f.date_select :day, :disabled => true, :order => [:day, :month] %> <%= 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_to_remote :commit, "Zeit Erfassen", :submit => :time_record, :url => {:action => "add_time_record"} %> <% end %>

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.

Thanks for your post - really great. I was just on the wrong way, now it
just works fine.

Best regards,
Andor