Hey , So i have a website that has a standard logo, and navigation. There is a section where all my "rails content" is placed. I am trying to figure out the best way to "wrap" the rails application with a standard html navigation template. I have discovered two ways and was wondering if anyone has an easier suggestion. 1) create a main layout called main.rthml in views/layouts. Then in routes.rb set default page to be this page. Inside main.rhtml i place a <div id=maincontent><%= @content_for_layout %></div> tag where all the output from my controllers go, using Ajax. the problem with this is if someone goes to /controller/method in the browser, the site template is gone. 2) at the top of each controller i can place a layout "main". The problem with this is using the Ajax method above repastes the entire html file, but prevents problem in #1. is there a better way then these 2 to separate the HTML and the controller output ? thanks adam
On Aug 18, 2005, at 6:49 AM, Adam Denenberg wrote:> Hey , > > So i have a website that has a standard logo, and navigation. > There is a section where all my "rails content" is placed. I am > trying to figure out the best way to "wrap" the rails application > with a standard html navigation template. I have discovered two > ways and was wondering if anyone has an easier suggestion. > > 1) create a main layout called main.rthml in views/layouts. Then > in routes.rb set default page to be this page. Inside main.rhtml i > place a <div id=maincontent><%= @content_for_layout %></div> tag > where all the output from my controllers go, using Ajax. the > problem with this is if someone goes to /controller/method in the > browser, the site template is gone. > > 2) at the top of each controller i can place a layout "main". The > problem with this is using the Ajax method above repastes the > entire html file, but prevents problem in #1.What you want to do is do layout "main" In your ApplicationController. Then all of your controllers will get this layout. Then, in your actions: if request.xml_http_request? render :partial => true else render end - Jamis
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jamis Buck wrote: (...snip...)> What you want to do is do > > layout "main" > > In your ApplicationController. Then all of your controllers will get > this layout. > > Then, in your actions: > > if request.xml_http_request? > render :partial => true > else > render > end >Sorry for asking noob questions, but noob is what I am so here we go: Why check for xml_http_request? And what are the output differences? Regards, - ------------------------------------------------------------------------ /*Ronny Hanssen*/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDBJ1TMRRzQX3ma+kRAk+KAJ4iBv/ANdKxZkk2HgGc4sENqMBt7ACgrXln 1Lw7MTsPgkASx+D3APSLNIc=Dxs9 -----END PGP SIGNATURE-----
Jamis Buck wrote:> What you want to do is do > > layout "main"I should add to Jamis'' response that the layout application.rhtml behaves like this automatically.> Then, in your actions: > > if request.xml_http_request? > render :partial => true > else > render > endAnother cool trick you can do to get the same effect is to use a choose_layout method: class MyController < AC::Base layout :choose_layout protected def choose_layout request.xhr? ? ''xhr'' : ''application'' end end I find using an xhr layout a good way to show notices and errors, assuming that you do that in your layout, that is. - Nicholas
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Nicholas Seckar wrote: (...snip...)> Another cool trick you can do to get the same effect is to use a > choose_layout method: > > class MyController < AC::Base > layout :choose_layout > > protected > > def choose_layout > request.xhr? ? ''xhr'' : ''application'' > end > end > > I find using an xhr layout a good way to show notices and errors, > assuming that you do that in your layout, that is. > > - Nicholas"What''s xhr?" the noob asks... :) Do you have to create the xhr layout, or is this some automagic stuff? - ------------------------------------------------------------------------ /*Ronny Hanssen*/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDBLnMMRRzQX3ma+kRAnryAKCa7rfFNjplZVEv2I5j7IN6l4CwEACfY8Fr ts+EWRSL12fZXgwB59hOOJ8=ZvsU -----END PGP SIGNATURE-----
On 18.8.2005, at 19.39, Ronny Hanssen wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Nicholas Seckar wrote: > (...snip...) > >> Another cool trick you can do to get the same effect is to use a >> choose_layout method: >> >> class MyController < AC::Base >> layout :choose_layout >> >> protected >> >> def choose_layout >> request.xhr? ? ''xhr'' : ''application'' >> end >> end >> >> I find using an xhr layout a good way to show notices and errors, >> assuming that you do that in your layout, that is. >> >> - Nicholas >> > > "What''s xhr?" the noob asks... :)XMLHttpRequest. I think Nicholas was just trying to avoid RSI (= repetitive strain injury ;-) in there.> Do you have to create the xhr layout, or is this some automagic stuff?Yes, you need to. Or well, you won''t because you probably don''t want to use a layout for AJAX (=the funky name for XHR usage) responses (they are not whole pages anyway). But then you should replace ''xhr'' with nil. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Jamis Buck wrote: (...snip...)> What you want to do is do > > layout "main" > > In your ApplicationController. Then all of your controllers will get > this layout. > > Then, in your actions: > > if request.xml_http_request? > render :partial => true > else > render > end > > - JamisHm... I am having problems recreating your suggestion. I have created a main.rhtml in layouts, and have added layout :main in application.rb. In my actions I have tried render, but it still seems that the controller chooses it''s own layout: class ApplicationController < ActionController::Base layout :main end class ArticlesController < ActionController::Base def show @article = Article.find(params[:id]) end end Browsing "http://localhost/articles/show/1" I''d expect to see results from the main.rhtml layout, but using the contents from the view/articles/show.rhtml file. But, it doesn''t, it still uses the application.rhtml layout. I''ve tried adding render in the show method: class ArticlesController < ActionController::Base def show @article = Article.find(params[:id]) render end end .. but without luck. Using render-partial doesn''t seem to smart either, since I then need /view/articles/_show.rhtml, which is of course easy but I can''t see how that fixes my layout problem? I think I must really be missing out on something here... Help? - ------------------------------------------------------------------------ /*Ronny Hanssen*/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDBL8WMRRzQX3ma+kRAkxZAKCZW+Q5QKua2HAtp/Gf1jEhlsDPiACfZVHJ abTjVIqcrIeXYjscccUAp04=lmNn -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Thx. I guessed it had something to do with that. I was confused about the layout though since, as you just said, it''d normally be nil for ajax requests. I still have problems getting this done properly though. I''ve sent a followup to this thread already regardning my issues on this. Thanks, - ------------------------------------------------------------------------ /*Ronny Hanssen*/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDBL/2MRRzQX3ma+kRAqViAKDUneETzqFwIh0efWQBd2hkmTsmCwCePEeU nZz+d3A9GRanInjdtFOvi0g=5kE+ -----END PGP SIGNATURE-----
Yet another solution: class ApplicationController < ActionController::Base layout :main, except = > [''ajax_action''] end class ArticlesController < ActionController::Base def show @article = Article.find(params[:id]) end def ajax_action end end On 8/18/05, Ronny Hanssen <ronnyh-7tg5dEkr+6sdnm+yROfE0A@public.gmane.org> wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > > > Jamis Buck wrote: > (...snip...) > > What you want to do is do > > > > layout "main" > > > > In your ApplicationController. Then all of your controllers will get > > this layout. > > > > Then, in your actions: > > > > if request.xml_http_request? > > render :partial => true > > else > > render > > end > > > > - Jamis > > Hm... I am having problems recreating your suggestion. I have created a > main.rhtml in layouts, and have added layout :main in application.rb. > In my actions I have tried render, but it still seems that the > controller chooses it''s own layout: > > class ApplicationController < ActionController::Base > layout :main > end > > class ArticlesController < ActionController::Base > def show > @article = Article.find(params[:id]) > end > end > > Browsing "http://localhost/articles/show/1" I''d expect to see results > from the main.rhtml layout, but using the contents from the > view/articles/show.rhtml file. But, it doesn''t, it still uses the > application.rhtml layout. I''ve tried adding render in the show method: > > class ArticlesController < ActionController::Base > def show > @article = Article.find(params[:id]) > render > end > end > > .. but without luck. Using render-partial doesn''t seem to smart either, > since I then need /view/articles/_show.rhtml, which is of course easy > but I can''t see how that fixes my layout problem? > > I think I must really be missing out on something here... Help? > > - ------------------------------------------------------------------------ > /*Ronny Hanssen*/ > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.0 (MingW32) > Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org > > iD8DBQFDBL8WMRRzQX3ma+kRAkxZAKCZW+Q5QKua2HAtp/Gf1jEhlsDPiACfZVHJ > abTjVIqcrIeXYjscccUAp04> =lmNn > -----END PGP SIGNATURE----- > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
this doesnt seem to be working for me still. In my controller i put def list store_location @event_pages, @events = paginate :event, :per_page => 10 if request.xml_http_request? render :partial => true else render end end and in application.rb i placed layout "main_layout" but it is still not applying the layout and using its own when i go directly in the browser to /events/list Am i missing anything else ? -adam On Aug 18, 2005, at 1:22 PM, Leon Leslie wrote:> Yet another solution: > > class ApplicationController < ActionController::Base > layout :main, except = > [''ajax_action''] > end > > class ArticlesController < ActionController::Base > def show > @article = Article.find(params[:id]) > end > > def ajax_action > > end > end > > > > On 8/18/05, Ronny Hanssen <ronnyh-7tg5dEkr+6sdnm+yROfE0A@public.gmane.org> wrote: > >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> >> >> Jamis Buck wrote: >> (...snip...) >> >>> What you want to do is do >>> >>> layout "main" >>> >>> In your ApplicationController. Then all of your controllers will get >>> this layout. >>> >>> Then, in your actions: >>> >>> if request.xml_http_request? >>> render :partial => true >>> else >>> render >>> end >>> >>> - Jamis >>> >> >> Hm... I am having problems recreating your suggestion. I have >> created a >> main.rhtml in layouts, and have added layout :main in application.rb. >> In my actions I have tried render, but it still seems that the >> controller chooses it''s own layout: >> >> class ApplicationController < ActionController::Base >> layout :main >> end >> >> class ArticlesController < ActionController::Base >> def show >> @article = Article.find(params[:id]) >> end >> end >> >> Browsing "http://localhost/articles/show/1" I''d expect to see results >> from the main.rhtml layout, but using the contents from the >> view/articles/show.rhtml file. But, it doesn''t, it still uses the >> application.rhtml layout. I''ve tried adding render in the show >> method: >> >> class ArticlesController < ActionController::Base >> def show >> @article = Article.find(params[:id]) >> render >> end >> end >> >> .. but without luck. Using render-partial doesn''t seem to smart >> either, >> since I then need /view/articles/_show.rhtml, which is of course easy >> but I can''t see how that fixes my layout problem? >> >> I think I must really be missing out on something here... Help? >> >> - >> --------------------------------------------------------------------- >> --- >> /*Ronny Hanssen*/ >> -----BEGIN PGP SIGNATURE----- >> Version: GnuPG v1.4.0 (MingW32) >> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org >> >> iD8DBQFDBL8WMRRzQX3ma+kRAkxZAKCZW+Q5QKua2HAtp/Gf1jEhlsDPiACfZVHJ >> abTjVIqcrIeXYjscccUAp04>> =lmNn >> -----END PGP SIGNATURE----- >> _______________________________________________ >> 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 > >
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I don''t know. I am having the same problem. The layout directive in application.rb doesn''t seem to have any effect at all. It still uses the actual controllers layout. :( - ------------------------------------------------------------------------ /*Ronny Hanssen*/ Adam Denenberg wrote:> this doesnt seem to be working for me still. In my controller i put > > def list > store_location > @event_pages, @events = paginate :event, :per_page => 10 > if request.xml_http_request? > render :partial => true > else > render > end > end > > and in application.rb i placed > > layout "main_layout" > > but it is still not applying the layout and using its own when i go > directly in the browser to /events/list > > Am i missing anything else ? > > -adam > > > On Aug 18, 2005, at 1:22 PM, Leon Leslie wrote: > >> Yet another solution: >> >> class ApplicationController < ActionController::Base >> layout :main, except = > [''ajax_action''] >> end >> >> class ArticlesController < ActionController::Base >> def show >> @article = Article.find(params[:id]) >> end >> >> def ajax_action >> >> end >> end >> >> >> >> On 8/18/05, Ronny Hanssen <ronnyh-7tg5dEkr+6sdnm+yROfE0A@public.gmane.org> wrote: >> > > > Jamis Buck wrote: > (...snip...) > >>>>> What you want to do is do >>>>> >>>>> layout "main" >>>>> >>>>> In your ApplicationController. Then all of your controllers will get >>>>> this layout. >>>>> >>>>> Then, in your actions: >>>>> >>>>> if request.xml_http_request? >>>>> render :partial => true >>>>> else >>>>> render >>>>> end >>>>> >>>>> - Jamis >>>>> > > Hm... I am having problems recreating your suggestion. I have created a > main.rhtml in layouts, and have added layout :main in application.rb. > In my actions I have tried render, but it still seems that the > controller chooses it''s own layout: > > class ApplicationController < ActionController::Base > layout :main > end > > class ArticlesController < ActionController::Base > def show > @article = Article.find(params[:id]) > end > end > > Browsing "http://localhost/articles/show/1" I''d expect to see results > from the main.rhtml layout, but using the contents from the > view/articles/show.rhtml file. But, it doesn''t, it still uses the > application.rhtml layout. I''ve tried adding render in the show method: > > class ArticlesController < ActionController::Base > def show > @article = Article.find(params[:id]) > render > end > end > > .. but without luck. Using render-partial doesn''t seem to smart either, > since I then need /view/articles/_show.rhtml, which is of course easy > but I can''t see how that fixes my layout problem? > > I think I must really be missing out on something here... Help? >-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDBP9SMRRzQX3ma+kRAqRFAKDfcjy2PTRJjxzDGEC9xYYrsXSfRQCgs/ST bU/Puquza30SrkS/NUk2EDo=4OS/ -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I am still not able to get the layout directive in the ApplicationController to actually do anything. The ArticlesController keeps using it''s own layout. Another question in regards to your sample. Doesn''t this mean that *any* controller that has an "ajax_action" action will be affected? And, for actions that is set to be "ajax_action", what layout is given then? Leon Leslie wrote:> Yet another solution: > > class ApplicationController < ActionController::Base > layout :main, except = > [''ajax_action''] > end > > class ArticlesController < ActionController::Base > def show > @article = Article.find(params[:id]) > end > > def ajax_action > > end > end > >- ------------------------------------------------------------------------ /*Ronny Hanssen*/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDBQBeMRRzQX3ma+kRAva3AJ9bnFN8/evO43zoaS72yJpnZDFyawCfedFj nPmECOSb9vQBTQ2w20Nptys=zaH/ -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I''ll answer this one myself. There were two gotchas that I had when digging through this: 1) The layout specification that were suggested in this thread was normally "main". Which is good. However, I picked the sample where it was suggested that it''d be :main. The first is good, the latter is wrong. Unless you have a method named main that returns a string. 2) Secondly, setting the layout in the application doesn''t really help at all, *if* you don''t get rid of the view belonging to the view in question. Lessons learned and applied to my code: I have renamed the main.rhtml to application.rhtml. Which means that I can skip the layout "main" directive in the application.rb, since it then by default looks for "application.rhtml" in the layout folder. Secondly - get rid of the view for the controller when you don''t want it to have it''s own and rather use the parent. If you keep the view there *it will not* select the application layout. My guess is that runtime, when entering the controller, it sets the layout to the view. And later, when trying to render it sees that it isn''t there and then looks at the application controller''s layout instead. This may be wrong, but thats the way it seems to me at least... Regards, - ------------------------------------------------------------------------ /*Ronny Hanssen*/ Ronny Hanssen wrote:> I don''t know. I am having the same problem. The layout directive in > application.rb doesn''t seem to have any effect at all. It still uses the > actual controllers layout. :( > > ------------------------------------------------------------------------ > /*Ronny Hanssen*/ > > Adam Denenberg wrote: > >>>this doesnt seem to be working for me still. In my controller i put >>> >>>def list >>> store_location >>> @event_pages, @events = paginate :event, :per_page => 10 >>> if request.xml_http_request? >>> render :partial => true >>> else >>> render >>> end >>> end >>> >>>and in application.rb i placed >>> >>>layout "main_layout" >>> >>>but it is still not applying the layout and using its own when i go >>>directly in the browser to /events/list >>> >>>Am i missing anything else ? >>> >>>-adam >>> >>> >>>On Aug 18, 2005, at 1:22 PM, Leon Leslie wrote: >>> >>> >>>>Yet another solution: >>>> >>>>class ApplicationController < ActionController::Base >>>> layout :main, except = > [''ajax_action''] >>>>end >>>> >>>>class ArticlesController < ActionController::Base >>>> def show >>>> @article = Article.find(params[:id]) >>>> end >>>> >>>> def ajax_action >>>> >>>> end >>>>end >>>> >>>> >>>> >>>>On 8/18/05, Ronny Hanssen <ronnyh-7tg5dEkr+6sdnm+yROfE0A@public.gmane.org> wrote: >>>> >>> >>> >>>Jamis Buck wrote: >>>(...snip...) >>> >>> >>>>>>>What you want to do is do >>>>>>> >>>>>>> layout "main" >>>>>>> >>>>>>>In your ApplicationController. Then all of your controllers will get >>>>>>>this layout. >>>>>>> >>>>>>>Then, in your actions: >>>>>>> >>>>>>> if request.xml_http_request? >>>>>>> render :partial => true >>>>>>> else >>>>>>> render >>>>>>> end >>>>>>> >>>>>>>- Jamis >>>>>>> >>> >>>Hm... I am having problems recreating your suggestion. I have created a >>>main.rhtml in layouts, and have added layout :main in application.rb. >>>In my actions I have tried render, but it still seems that the >>>controller chooses it''s own layout: >>> >>>class ApplicationController < ActionController::Base >>> layout :main >>>end >>> >>>class ArticlesController < ActionController::Base >>> def show >>> @article = Article.find(params[:id]) >>> end >>>end >>> >>>Browsing "http://localhost/articles/show/1" I''d expect to see results >>>from the main.rhtml layout, but using the contents from the >>>view/articles/show.rhtml file. But, it doesn''t, it still uses the >>>application.rhtml layout. I''ve tried adding render in the show method: >>> >>>class ArticlesController < ActionController::Base >>> def show >>> @article = Article.find(params[:id]) >>> render >>> end >>>end >>> >>>.. but without luck. Using render-partial doesn''t seem to smart either, >>>since I then need /view/articles/_show.rhtml, which is of course easy >>>but I can''t see how that fixes my layout problem? >>> >>>I think I must really be missing out on something here... Help? >>> > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDBQ4BMRRzQX3ma+kRAs0gAKDiszKymRqdvDYobwF/8qTsXZn2tACgq1Qg awP24OPe1Q+deF2ILayiZPU=bF1G -----END PGP SIGNATURE-----
Ronny, thanks for this post. However i have a question. If you delete the view for every controller, how do you get any of their output into the application.rb layout? How will anything get placed in <%= @content_for_layout %> inside application.rb, if you delete all the views ? adam On Aug 18, 2005, at 6:38 PM, Ronny Hanssen wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > I''ll answer this one myself. There were two gotchas that I had when > digging through this: > > 1) The layout specification that were suggested in this thread was > normally "main". Which is good. However, I picked the sample where it > was suggested that it''d be :main. The first is good, the latter is > wrong. Unless you have a method named main that returns a string. > > 2) Secondly, setting the layout in the application doesn''t really help > at all, *if* you don''t get rid of the view belonging to the view in > question. > > Lessons learned and applied to my code: > I have renamed the main.rhtml to application.rhtml. Which means that I > can skip the > layout "main" > directive in the application.rb, since it then by default looks for > "application.rhtml" in the layout folder. > > Secondly - get rid of the view for the controller when you don''t > want it > to have it''s own and rather use the parent. If you keep the view there > *it will not* select the application layout. > > My guess is that runtime, when entering the controller, it sets the > layout to the view. And later, when trying to render it sees that it > isn''t there and then looks at the application controller''s layout > instead. This may be wrong, but thats the way it seems to me at > least... > > Regards, > - > ---------------------------------------------------------------------- > -- > /*Ronny Hanssen*/ > > > Ronny Hanssen wrote: > >> I don''t know. I am having the same problem. The layout directive in >> application.rb doesn''t seem to have any effect at all. It still >> uses the >> actual controllers layout. :( >> >> --------------------------------------------------------------------- >> --- >> /*Ronny Hanssen*/ >> >> Adam Denenberg wrote: >> >> >>>> this doesnt seem to be working for me still. In my controller i >>>> put >>>> >>>> def list >>>> store_location >>>> @event_pages, @events = paginate :event, :per_page => 10 >>>> if request.xml_http_request? >>>> render :partial => true >>>> else >>>> render >>>> end >>>> end >>>> >>>> and in application.rb i placed >>>> >>>> layout "main_layout" >>>> >>>> but it is still not applying the layout and using its own when i go >>>> directly in the browser to /events/list >>>> >>>> Am i missing anything else ? >>>> >>>> -adam >>>> >>>> >>>> On Aug 18, 2005, at 1:22 PM, Leon Leslie wrote: >>>> >>>> >>>> >>>>> Yet another solution: >>>>> >>>>> class ApplicationController < ActionController::Base >>>>> layout :main, except = > [''ajax_action''] >>>>> end >>>>> >>>>> class ArticlesController < ActionController::Base >>>>> def show >>>>> @article = Article.find(params[:id]) >>>>> end >>>>> >>>>> def ajax_action >>>>> >>>>> end >>>>> end >>>>> >>>>> >>>>> >>>>> On 8/18/05, Ronny Hanssen <ronnyh-7tg5dEkr+6sdnm+yROfE0A@public.gmane.org> wrote: >>>>> >>>>> >>>> >>>> >>>> Jamis Buck wrote: >>>> (...snip...) >>>> >>>> >>>> >>>>>>>> What you want to do is do >>>>>>>> >>>>>>>> layout "main" >>>>>>>> >>>>>>>> In your ApplicationController. Then all of your controllers >>>>>>>> will get >>>>>>>> this layout. >>>>>>>> >>>>>>>> Then, in your actions: >>>>>>>> >>>>>>>> if request.xml_http_request? >>>>>>>> render :partial => true >>>>>>>> else >>>>>>>> render >>>>>>>> end >>>>>>>> >>>>>>>> - Jamis >>>>>>>> >>>>>>>> >>>> >>>> Hm... I am having problems recreating your suggestion. I have >>>> created a >>>> main.rhtml in layouts, and have added layout :main in >>>> application.rb. >>>> In my actions I have tried render, but it still seems that the >>>> controller chooses it''s own layout: >>>> >>>> class ApplicationController < ActionController::Base >>>> layout :main >>>> end >>>> >>>> class ArticlesController < ActionController::Base >>>> def show >>>> @article = Article.find(params[:id]) >>>> end >>>> end >>>> >>>> Browsing "http://localhost/articles/show/1" I''d expect to see >>>> results >>>> from the main.rhtml layout, but using the contents from the >>>> view/articles/show.rhtml file. But, it doesn''t, it still uses the >>>> application.rhtml layout. I''ve tried adding render in the show >>>> method: >>>> >>>> class ArticlesController < ActionController::Base >>>> def show >>>> @article = Article.find(params[:id]) >>>> render >>>> end >>>> end >>>> >>>> .. but without luck. Using render-partial doesn''t seem to smart >>>> either, >>>> since I then need /view/articles/_show.rhtml, which is of course >>>> easy >>>> but I can''t see how that fixes my layout problem? >>>> >>>> I think I must really be missing out on something here... Help? >>>> >>>> >> >> >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.0 (MingW32) > Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org > > iD8DBQFDBQ4BMRRzQX3ma+kRAs0gAKDiszKymRqdvDYobwF/8qTsXZn2tACgq1Qg > awP24OPe1Q+deF2ILayiZPU> =bF1G > -----END PGP SIGNATURE----- > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >
In the app/views/layouts directory, if there is a layout of the same name as the controller it will use that layout overriding you default setting in the application controller. Remove all rhtml files in the app/views/layouts directory and you won''t have a problem. -andy -- Andrew Stone
On 8/18/05, Andrew Stone <stonelists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In the app/views/layouts directory, if there is a layout of the same > name as the controller it will use that layout overriding you default > setting in the application controller. Remove all rhtml files in the > app/views/layouts directory and you won''t have a problem.That should be "all of them except application.rhtml or the layout specified in the application controller", right?
Yes, all of them except the one (which you must have) defined in the application controller. Without defining: layout ''my_layout'' in application.rb, you will get errors if there is not a corresponding layout (.rhtml) file in the app/views/layouts dir for the controller you are trying to access. So, to recap, in application.rb have a line similar to: layout ''my_layout'' in app/views/layouts: there should be a file: my_layout.rhtml this is the only file you will need to have in that directory (if you want them all to use the same layout). -andy -- Andrew Stone
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Sorry, typo on my behalf. You have to get rid of the *layout* for the current action. Sorry. Also note. You can also just set: layout nil and you''ll get the same results. Regards, - ------------------------------------------------------------------------ /*Ronny Hanssen*/ Adam Denenberg wrote:> Ronny, > > thanks for this post. However i have a question. If you delete the > view for every controller, how do you get any of their output into the > application.rb layout? > > How will anything get placed in <%= @content_for_layout %> inside > application.rb, if you delete all the views ? > > adam >-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDBV0aMRRzQX3ma+kRAhbcAJwKW5tVbHNb6MWyQ2SxHMovTe/S1QCfSvki z6MFz+tmrEql0CKVxPSXHQk=sB4B -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I obviously have to be getting real tired by now... :/ You have to get rid of the layout for the current *controller*, sigh :) - ------------------------------------------------------------------------ /*Ronny Hanssen*/ Ronny Hanssen wrote:> Sorry, typo on my behalf. You have to get rid of the *layout* for the > current action. Sorry. > > Also note. You can also just set: > layout nil > and you''ll get the same results. > > Regards, > > ------------------------------------------------------------------------ > /*Ronny Hanssen*/ > > Adam Denenberg wrote: > >>>Ronny, >>> >>> thanks for this post. However i have a question. If you delete the >>>view for every controller, how do you get any of their output into the >>>application.rb layout? >>> >>>How will anything get placed in <%= @content_for_layout %> inside >>>application.rb, if you delete all the views ? >>> >>>adam >>> >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDBV9xMRRzQX3ma+kRAlZSAJ9rumbJod9IqVzqGBTEeYrNaHEV1QCglT4r G/VHO1aguJME7DelzGIWX4o=ukp/ -----END PGP SIGNATURE-----