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
<h1>Listing all positions</h1>
<%= javascript_include_tag :defaults %>
<table cellpadding="5" cellspacing="0">
<tr>
<th align="left">Job Title</th>
<th align="left">Salary</th>
<th align="left">Location</th>
<th align="left">Action</th>
</tr>
<%= render(:partial => ''position'', :collection =>
@positions) %>
</table>
<%= 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 %>
<br />
<%= link_to ''New position'', :action =>
''new'' %>
#_position.rhtml (partial)
<tr>
<tr>
<td align="left" valign="top">
<span id=''<%= position.id %>''>
<%= link_to position.job_title, :action => ''show'',
:id => position %>
</span>
</td>
<td align="left" valign="top"><%=
position.salary %></td>
<td align="left" valign="top"><%=
position.location %></td>
</tr>
<tr>
<td align="left" rowspan="5"
colspan="3"><%= position.description
%></td>
<tr><td><%= link_to ''Edit'', :action =>
''edit'', :id => position
%></td></tr>
<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
position?'',
:complete =>
"$(''#{position.id}'').style.textDecoration =
''line-through''"
) %></td></tr>
<tr><td><%= link_to ''apply'', { :action
=> ''apply'', :id => position
}, :confirm => ''Are you sure you wish to apply for this
position?''
%></td></tr>
</tr>
<tr>
<td id="info">Currently <strong><%=
position.applicants %></strong>
applicants for this position.</td>
</tr>
</tr>
#_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])
@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 Fuchs for pointing me in teh right direction (and
scriptacuolus)
Kev