How the heck do you do it? I can''t put this in the controller: render(:layout => false) ...or it will never show the layout even the first time before the Ajax call. So I guess you have to use some sort of conditioal, but what''s the condition? Here''s the pseudo code I want to add to my controller: def show_list if :is_ajax render(:layout => false) end # do stuff end Any tips for a newbie? :-) -- Posted via http://www.ruby-forum.com/.
Try for ajax requests xhr? On 12/12/05, Sean Schertell <sean-ZFxOO9cya7fR7s880joybQ@public.gmane.org> wrote:> > How the heck do you do it? I can''t put this in the controller: > render(:layout => false) > > ...or it will never show the layout even the first time before the Ajax > call. So I guess you have to use some sort of conditioal, but what''s > the condition? > > Here''s the pseudo code I want to add to my controller: > > def show_list > if :is_ajax > render(:layout => false) > end > # do stuff > end > > > Any tips for a newbie? > > :-) > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Daniel ----- wrote:> Try for ajax requests > > xhr?Is that a symbol? Would my conditional look like this? if :xhr? #blah blah end I tried that and it seems to always return true :( So I''m still scratching my head. Am I missing something really stupid here? Surely I''m not the first person to ever not want a second layout when a partial is redered with ajax, right? How do you guys do this? :) -- Posted via http://www.ruby-forum.com/.
On Dec 11, 2005, at 10:58 PM, Sean Schertell wrote:> Daniel ----- wrote: >> Try for ajax requests >> >> xhr? > > > Is that a symbol? Would my conditional look like this? > if :xhr? > #blah blah > end > > I tried that and it seems to always return true :( > > So I''m still scratching my head. Am I missing something really stupid > here? Surely I''m not the first person to ever not want a second > layout > when a partial is redered with ajax, right? > > How do you guys do this? :) >if request.xhr? # do ajax stuff else # do normal stuff end Cheers- -Ezra Zygmuntowicz WebMaster Yakima Herald-Republic Newspaper ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org 509-577-7732
Ezra Zygmuntowicz wrote:> if request.xhr? > # do ajax stuff > else > # do normal stuff > endEzra that''s awesome thanks! And it *almost* works too. The conditional does seem to be working. But strangely enough, if I let it render with the extra layout, there are no errors. But if I use your conditional to stop the second layout, I get this love note from Rails: NoMethodError in Nova#members Showing app/views/partial/_paginator.rhtml where line #4 raised: You have a nil object when you didn''t expect it! The error occured while evaluating nil.current Extracted source (around line #4): 1: <div class="paginator"> 2: <div class="button"> 3: <%4: if paginator.current.previous 5: link_to ''<span class="hidden"><<</span>'', 6: { :page => paginator.current.previous }, 7: :class => ''back'' What the...? -- Posted via http://www.ruby-forum.com/.
Whats the actual code part for your rendering? I''ve just been using a mix of partials and regular templates lately to update sections of the page with out any real issues. If I''m rendering a partial my controller simply has: render :partial => "/partial/name/here" Or if I have a non-partial I have render :action => "action", :layout => false Either way they both seem to work. It is important to remember though that just calling the render() method doesn''t actually execute the corresponding action method in the controller. You have to call them separately in these cases. Where I usually miss something is in the views them selves and I''ll spell the id for the div tag wrong or something. If you do that then either nothing gets updated or other odd things happen. So post some code, and we''ll see whats happening. -Nick On 12/12/05, Sean Schertell <sean-ZFxOO9cya7fR7s880joybQ@public.gmane.org> wrote:> Ezra Zygmuntowicz wrote: > > if request.xhr? > > # do ajax stuff > > else > > # do normal stuff > > end > > Ezra that''s awesome thanks! And it *almost* works too. The conditional > does seem to be working. But strangely enough, if I let it render with > the extra layout, there are no errors. But if I use your conditional to > stop the second layout, I get this love note from Rails: > > NoMethodError in Nova#members > Showing app/views/partial/_paginator.rhtml where line #4 raised: > > You have a nil object when you didn''t expect it! > The error occured while evaluating nil.current > Extracted source (around line #4): > > 1: <div class="paginator"> > 2: <div class="button"> > 3: <%> 4: if paginator.current.previous > 5: link_to ''<span class="hidden"><<</span>'', > 6: { :page => paginator.current.previous }, > 7: :class => ''back'' > > > What the...? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Thanks very much Nick. In my case, the problem was resolved by simply moving Ezra code to the bottom of my controller definition. I can''t honestly claim to understand why that worked - but it did so all is well. Thanks everyone :) -- Posted via http://www.ruby-forum.com/.