Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 22nd, 2006, 1:06 PM   #1
matthewvb
Newbie
 
matthewvb's Avatar
 
Join Date: Sep 2006
Posts: 23
Rep Power: 0 matthewvb is on a distinguished road
Send a message via AIM to matthewvb
controllers & AJAX

I have a controller that renders a partial which looks like this: (traditional rendering)

render :partial => "feed", :object => @feed

question is: how can I call this method from the view and implement some cool AJAX where I get a loading spinner while the text is rendering then loads all at once?

I can do it with a form with this code:

<%= form_remote_tag :url => {:action => 'view'}, 
   :update => 'feed', :complete => visual_effect(:blind_down, 'feed'), 
   :before => %(Element.show('spinner')),
   :success => %(Element.hide('spinner')) %>

but i can't figure out how to implement the same type of comments when just calling the controller instead of having to use a form or a link (link_to_remote) in order access the content.

i'd be open to doing away with the controller and just having all the code in the view area, but i'm still looking to have the AJAX before/success elements implemented.

Thanks in advance for the help!
-matthew
__________________
matthewvb
www.matthewvb.com
matthewvb is offline   Reply With Quote
Old Oct 23rd, 2006, 2:02 PM   #2
matthewvb
Newbie
 
matthewvb's Avatar
 
Join Date: Sep 2006
Posts: 23
Rep Power: 0 matthewvb is on a distinguished road
Send a message via AIM to matthewvb
I have it figured out. I pulled the javascript from the source and put that in a body onload tag.

thanks all!
__________________
matthewvb
www.matthewvb.com
matthewvb is offline   Reply With Quote
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
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Something like AJAX Writlaus JavaScript and Client-Side Browser Scripting 4 Dec 20th, 2006 2:44 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:23 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC