Forum: Ruby on Rails AJAX - update item forms problem

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.
Michael M. (Guest)
on 2006-04-19 10:39
I have a table showing some records from the database. These records
should be always ordered by some datetime field. The list of items is
changed by AJAX using RJS scripts and edits are done by showing and
hiding an update form under a chosen row. Adding and updating rows works
great but my problem is when the order of items is changed after making
some AJAX datetime updates update forms of these changed items are not
filled with proper item data anymore when the form is shown. It seems to
me the initial order of forms is remembered somewhere and doesn't

Obviously I'm doing sth wrong here.
Any help is appreciated. Here is how I do it.

<tr id="workout_edit_<%= %>" style="display:none;">
    <td colspan="7" style="background-color: #eee; padding: 10;">
        <div id="workout_error_<%= %>">

    <div id="workout_error_list_<%= %>">
        <%= error_messages_for 'workout' %>

<%= form_remote_tag :url => { :action => 'update', :id => workout },
:html => { :id => "workout_form_#{}" } %>
<% @workout = workout %>
  <%= render :partial => 'update_form' %>
<%= end_form_tag %>



  def show_workout_update_form
    @workout_id = params[:id]

  def hide_workout_update_form
    @workout_id = params[:id]

  def update
    @workout = Workout.find(params[:id])
    @workout.exercises_count = @workout.exercises.count
    @saved = @workout.update_attributes(params[:workout])

    return if request.xhr?  # render RJS instead

if @saved
	page.hide "workout_edit_#{}"
	flash[:notice] = "Workout updated."
	session[:workout_yellow] = 'location.reload'
	page.hide "workout_edit_#{}"
	page.replace_html "workout_error_list_#{}",
	page.replace_html "workout_form_#{}", :partial =>
	page.visual_effect :appear, "workout_edit_#{}",
:duration => 0.5

<strong>Edit workout</strong>


<p><label for="workout_name">Name</label><br/>
<%= text_field 'workout', 'name'  %></p>
<p><label for="workout_description">Notes</label><br/>
<%= text_area 'workout', 'description', :rows => 3  %></p>
<p><label for="workout_started_at">Start time</label><br/>
<%= datetime_select 'workout', 'started_at', :start_year => 1980,
:end_year => 2010  %></p>
   <%= submit_tag "Update", :class => 'button' %>

  or <span class="red">
    <%= link_to_remote 'Cancel', :url => { :action =>
'hide_workout_update_form', :id => @workout } %>


page.visual_effect :appear, "workout_edit_#{@workout_id.to_s}",
:duration => 0.5

page.hide "workout_edit_#{@workout_id.to_s}"
Michael M. (Guest)
on 2006-04-19 15:38
Fixed already by this:

  def show_workout_update_form
    @workout_id = params[:id]
    @workout = Workout.find(@workout_id)
    render :update do |page|

      page.replace_html "workout_form_#{@workout_id.to_s}", :partial =>
'update_form', :object => @workout
      page.visual_effect :appear, "workout_form_#{@workout_id.to_s}",
:duration => 0.5
This topic is locked and can not be replied to.