I have the following code in my view: <html> <head> <title>Ajax Demo</title> <%= javascript_include_tag "prototype" %> <%= javascript_include_tag :defaults %> </head> <body> <div id="myDiv"> This will go away </div> <%= link_to_remote "Do Magic", :url => { :action => "DoMagic" }, :complete => visual_effect(:fade, "myDiv", :duration => 1.5), :html => {:style=>"background-color: #0e0;"} %> </body> </html> And this in my controller: class DemoController < ApplicationController def index end def DoMagic render_partial false end end The problem I''m having is twofold: 1. First, no matter where I place my :html=>{} settings or what I put in it, it gets ignored. The style is never applied. 2. Using Firebog to watch my AJAX request I see that I keep getting an error back, even though it works in the end. Here is the error I see coming back in Firebug: NoMethodError in DemoController#DoMagic - Now I''ve tried using "render_partial false", "render(:partial=>false", etc. but nothing works to get rid of this error message. Note: I know this is a trivial example and that my remote call does nothing, I just wanted to get this working first so I could add my logic later. Thanks for your help. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
first off, the javascript_include_tag for prototype is redundant, as prototype is included in the defaults. second, try this <div id="my_div">This will go away</div> <%= link_to_remote "Do Magic", :url => {:action => "DoMagic"}) -%> then in your controller: def DoMagic render :update do |page| page.visual_effect :fade, ''my_div'', :duration => 1.5 end end your browser will make an ajax request when the link is clicked, the server will respond with some javascript which will be evaulated and your div should fade out. On 9/27/06, Leo Silver <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I have the following code in my view: > > <html> > <head> > <title>Ajax Demo</title> > <%= javascript_include_tag "prototype" %> > <%= javascript_include_tag :defaults %> > </head> > <body> > <div id="myDiv"> > This will go away > </div> > <%= link_to_remote "Do Magic", :url => { :action => "DoMagic" }, > :complete => visual_effect(:fade, "myDiv", :duration => 1.5), > :html => {:style=>"background-color: #0e0;"} %> > </body> > </html> > > And this in my controller: > > class DemoController < ApplicationController > > def index > end > > def DoMagic > render_partial false > end > > end > > > The problem I''m having is twofold: > 1. First, no matter where I place my :html=>{} settings or what I put in > it, it gets ignored. The style is never applied. > 2. Using Firebog to watch my AJAX request I see that I keep getting an > error back, even though it works in the end. Here is the error I see > coming back in Firebug: NoMethodError in DemoController#DoMagic > - Now I''ve tried using "render_partial false", "render(:partial=>false", > etc. but nothing works to get rid of this error message. > > Note: I know this is a trivial example and that my remote call does > nothing, I just wanted to get this working first so I could add my logic > later. > > Thanks for your help. > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Chris Hall wrote:> first off, the javascript_include_tag for prototype is redundant, as > prototype is included in the defaults. > > second, try thisThanks a bunch! It''s working now without the error. The only issue I have left is trying to apply my CSS style to the link_to_remote. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Vishnu Gopal
2006-Sep-27 17:29 UTC
Re: Problem with link_to_remote/render_partial and :html
link_to_remote has three parameters, last two of which is a hash. http://rubyonrails.org/api/classes/ActionView/Helpers/PrototypeHelper.html#M000412 So do this: <%= link_to_remote("Do Magic", { :url => { :action => "DoMagic" } }, {:style=>"background-color: #0e0;"}) %> (last parameter is the html_options) Vish On 9/27/06, Leo Silver <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Chris Hall wrote: > > first off, the javascript_include_tag for prototype is redundant, as > > prototype is included in the defaults. > > > > second, try this > > Thanks a bunch! It''s working now without the error. The only issue I > have left is trying to apply my CSS style to the link_to_remote. > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---