Forum: Ruby on Rails Updating text with Ajax and link_to_remote

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.
kevin.jackson (Guest)
on 2005-11-12 12:49
(Received via mailing list)
Hi all,

I finally got what I wanted to happen, here's the source for everyones
reference should anyone else need to do something similar...

<h1>Listing all positions</h1>
<%= javascript_include_tag :defaults %>
<table cellpadding="5" cellspacing="0">
    <th align="left">Job Title</th>
    <th align="left">Salary</th>
    <th align="left">Location</th>
    <th align="left">Action</th>

  <%= render(:partial => 'position', :collection => @positions) %>


<%= link_to 'Previous page', { :page => @position_pages.current.previous
} if @position_pages.current.previous %>
<%= link_to 'Next page', { :page => } if %>

<br />

<%= link_to 'New position', :action => 'new' %>

#_position.rhtml (partial)
    <td align="left" valign="top">
      <span id='<%= %>'>
    <%= link_to position.job_title, :action => 'show', :id => position
    <td align="left" valign="top"><%= position.salary %></td>
    <td align="left" valign="top"><%= position.location %></td>
    <td align="left" rowspan="5" colspan="3"><%= position.description
    <tr><td><%= link_to 'Edit', :action => 'edit', :id => position
    <tr><td><%= link_to 'Destroy', { :action => 'destroy', :id =>
position }, :confirm => 'Are you sure?' %></td></tr>
    <tr><td><%= link_to_remote('close',
                :update => 'info',
                 :url => { :action => :close, :id => position },
                :confirm => 'Are you sure you wish to close this
                :complete => "$('#{}').style.textDecoration =
                ) %></td></tr>
    <tr><td><%= link_to 'apply', { :action => 'apply', :id => position
}, :confirm => 'Are you sure you wish to apply for this position?'
    <td id="info">Currently <strong><%= position.applicants %></strong>
applicants for this position.</td>

#_close.rhtml partial
<em>The position [ <%= @position.job_title %> ] is now closed.</em>

#close method of positions_controller
 def close
    @position = Position.find(params[:id])
      render :partial => 'close'

This should give you an updated info div *and* a change of text-style
for the id specified in the :complete param.  If you wanted to highlight
(Yellow fade) instead of line-through, simply replace
:complete => "$('#{}').style.textDecoration = 'line-through'"
:complete => visual_effect(:highlight,

Hope this helps other people stuck with ajax and rails...

Thanks to Thomas Fuchs for pointing me in teh right direction (and

This topic is locked and can not be replied to.