Forum: Ruby on Rails Ajax and tables

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.
Aa575b7606897a056f073f0f148804dd?d=identicon&s=25 Gareth Reeves (Guest)
on 2006-02-21 00:51
Guys,

I want to be able to update the contents of a table without dedrawing
the entire thing. Basically, if the user clicks on the 2nd column then i
want to turn that cell red, the 3rd green and the 4th blue.

I have the table drawing correctly now but not updating correctly. I
can't get the update to work on the div unless its inside the table
cell. I was hoping to have the div around the entire row but when I do
that, the contents of the ajax update show up above the table.

Does anyone have a good suggestion of how to do this?


Code snippets below

Thanks, Gareth

Here row, done for each feature.

  <tr>
    <td><%=h feature.description %></td>

	<% if @session[:vendor] %>
		<% impl = feature.implementation( @session[:vendor].id ) %>
		<div id='<%= feature.id  %>'>
		<td bgcolor =<%= impl.supports( FeatureImplementation::YES ) ? 'green'
: 'white' %>>
			<%= link_to_remote "click",
				:url => {:action => 'set_implementation', :id => impl.id, :value =>
FeatureImplementation::YES },
				:update => feature.id %>
		</td>

		<td bgcolor =<%= impl.supports( FeatureImplementation::SPECIAL ) ?
'yellow' : 'white' %>>
			<%= link_to_remote "click",
				:url => {:action => 'set_implementation', :id => impl.id, :value =>
FeatureImplementation::SPECIAL },
				:update => feature.id %>
		</td>
		<td bgcolor =<%= impl.supports( FeatureImplementation::CUSTOM ) ?
'brown' : 'white' %>>
			<%= link_to_remote "click",
				:url => {:action => 'set_implementation', :id => impl.id, :value =>
FeatureImplementation::CUSTOM },
				:update => feature.id %>
		</td>
		<td bgcolor =<%= impl.supports( FeatureImplementation::NO ) ? 'red' :
'white' %>>
			<%= link_to_remote "click",
				:url => {:action => 'set_implementation', :id => impl.id, :value =>
FeatureImplementation::NO },
				:update => feature.id %>
		</td>
		</div>
	<% end %>
    <td><%= link_to 'Edit', :action => 'edit', :id => feature if
@session[:user] %></td>
    <td><%= link_to 'Destroy', { :action => 'destroy', :id => feature },
:confirm => 'Are you sure?' if @session[:user] %></td>

  </tr>

And the action in the controller...

  def set_implementation
    puts 'set_implmplementation'
    impl = FeatureImplementation.find( params[:id] )
    impl.value = params[:value]
    impl.save()

    render_text "X"  # this should return the entire row
  end
This topic is locked and can not be replied to.