View Single Post
Old Aug 30th, 2007, 1:47 PM   #3
dark_omen
Hobbyist Programmer
 
Join Date: Dec 2004
Posts: 125
Rep Power: 4 dark_omen is on a distinguished road
Send a message via AIM to dark_omen
I did something with ajax on my rails site (http://boozrs.com) . The thing is I never could get the form_remote_tag to work properly with :update => 'someId', but something like this does work:
In view:
<%= image_tag('/images/indicator.gif', :border => 0, :id => 'posting', :style=> 'display: none;') %>
		<% form_remote_tag(:url => {:action => 'comment', :user_id => session[:user_id]}, :before => "Element.show('posting')", :success => "Element.hide('posting')") do %>
			<p><label>Comment</label><br/>
			<textarea name="comment" rows="10" cols="50"></textarea></p>
			<input type="submit" value="Add A Comment" />
		<% end %>
And the controller:
def comment
  #do stuff here specific to what you want to do
  render :update do |page|
    page.replace_html  'comments', :partial => 'comments' #you can pass objects and other stuff here, if you want
  end
end
dark_omen is offline   Reply With Quote