Updating text with Ajax and link_to_remote

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…

#list.rhtml

Listing all positions

<%= javascript_include_tag :defaults %>

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

Job Title Salary Location Action

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


<%= link_to ‘New position’, :action => ‘new’ %>

#_position.rhtml (partial)

<%= link_to position.job_title, :action => 'show', :id => position %> <%= position.salary %> <%= position.location %> <%= position.description %> <%= link_to 'Edit', :action => 'edit', :id => position %> <%= link_to 'Destroy', { :action => 'destroy', :id => position }, :confirm => 'Are you sure?' %> <%= link_to_remote('close', :update => 'info', :url => { :action => :close, :id => position }, :confirm => 'Are you sure you wish to close this position?', :complete => "$('#{position.id}').style.textDecoration = 'line-through'" ) %> <%= link_to 'apply', { :action => 'apply', :id => position }, :confirm => 'Are you sure you wish to apply for this position?' %> Currently <%= position.applicants %> applicants for this position.

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

#close method of positions_controller
def close
@position = Position.find(params[:id])
@position.close
if @position.save
render :partial => ‘close’
end
end

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 => “$(’#{position.id}’).style.textDecoration = ‘line-through’”
with
:complete => visual_effect(:highlight, position.id)

Hope this helps other people stuck with ajax and rails…

Thanks to Thomas F. for pointing me in teh right direction (and
scriptacuolus)

Kev