Why do I lose the application.rhtml template when I define a layout in a controller? This seems to violate DRY. The same problem also occurs when using a general layout for a controller, such as app/views/layouts/data.rhtml for DataController. -- 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 -~----------~----~----~----~------~----~------~--~---
Because a layout that corresponds to your controller name allows you to override the default application layout. Or conversely, any controller without a layout defined automatically inherits the application layout. You are not required to create a layout for each controller. Heck you don''t even have to create a view template. You can render directly to the response that is sent to the user agent. For example, render :text => ''Hello World!'' in an action will spit out Hello World!. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 9/22/06, Carl Johnson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Why do I lose the application.rhtml template when I define a layout in a > controller? This seems to violate DRY.I haven''t used it, but this looks like what you want to do: http://nested-layouts.rubyforge.org/ That said, I think it should also be possible to rethink your layout and use partials to avoid RY. -Pawel --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
OK. Well, I''m trying to follow DRY but running into problems with my site''s header and footer. Every single page of my site will have the same header and footer. I have that in application.rhtml right now. It looks like I will have to create _header and _footer partials and include those instead when I have shared layouts. Not a lot of repeating though... I''m probably just being too picky. :) Thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
You don''t have to do that. Just don''t create layouts for your controllers. Just view templates for your actions. The view templates will automatically use the application layout. On 9/22/06, Carl Johnson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > OK. Well, I''m trying to follow DRY but running into problems with my > site''s header and footer. Every single page of my site will have the > same header and footer. I have that in application.rhtml right now. It > looks like I will have to create _header and _footer partials and > include those instead when I have shared layouts. Not a lot of repeating > though... I''m probably just being too picky. :) Thanks! > > -- > 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 -~----------~----~----~----~------~----~------~--~---
I''m a newbie, maybe I''m missing something... I know if I have an action "browse" in DataController that it will use the template app/views/data/browse.rhtml. But I want that "browse" template to be used for a bunch of actions in multiple controllers. That''s why I tried to simply call it "standard" and define the layout in each controller. -- 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 -~----------~----~----~----~------~----~------~--~---
define app/views/layouts/application.rhtml define app/views/<my_share_folder>/_<shared_partial>.rhtml define app/views/<controller>/<action>.rhtml within app/views/<controller>/<action>.rhtml file render the shared partial like so render(:partial => ''<my_share_folder>/<shared_partial>'', ...) Your action will get the appropriate view, embed the shared partial, and use the application layout to wrap the templates. If you include a path to the partial, app/views is considered the root, otherwise Rails looks in app/views/<controller>. I suggest reading Agile Web Development with Rails. This is specifically covered in the book. On 9/22/06, Carl Johnson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I''m a newbie, maybe I''m missing something... I know if I have an action > "browse" in DataController that it will use the template > app/views/data/browse.rhtml. But I want that "browse" template to be > used for a bunch of actions in multiple controllers. That''s why I tried > to simply call it "standard" and define the layout in each controller. > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Yeah, I understand the logic, just having trouble wrapping my head around what I''m trying to do I guess. I have various little "info boxes" that pull data from different controllers, and these will be on the side of various screens. Sort of a portal view. I think my problem is that I am using partials for data display only. If I use a shared partial for the standard HTML template as well, that ought to accomplish what I need. Thanks for your help! Carl -- 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 -~----------~----~----~----~------~----~------~--~---
On 9/22/06, Carl Johnson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Yeah, I understand the logic, just having trouble wrapping my head > around what I''m trying to do I guess. I have various little "info boxes" > that pull data from different controllers, and these will be on the side > of various screens. Sort of a portal view. > > I think my problem is that I am using partials for data display only. If > I use a shared partial for the standard HTML template as well, that > ought to accomplish what I need. > > Thanks for your help! > > Carl > > --I was struggling a bit with layouts as well. I new about partials , but then I read up on the @content_for . That is pretty powerful. In one layout I can have multiple partials whereever I want. Check the api (sorry don''t have the link) As an example though - In my view I have this , with the html and code between - <% content_for ''postform'' do -%> <% end-%> then in my layout i just decide where that goes and put the @content_for_postform Hope this helps and is relevant. Stuart --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 9/23/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 9/22/06, Carl Johnson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > Yeah, I understand the logic, just having trouble wrapping my head > > around what I''m trying to do I guess. I have various little "info boxes" > > that pull data from different controllers, and these will be on the side > > of various screens. Sort of a portal view. > > > > I think my problem is that I am using partials for data display only. If > > I use a shared partial for the standard HTML template as well, that > > ought to accomplish what I need. > > > > Thanks for your help! > > > > Carl > > > > -- > I was struggling a bit with layouts as well. I new about partials , > but then I read up on the @content_for . That is pretty powerful. In > one layout I can have multiple partials whereever I want. Check the > api (sorry don''t have the link) > As an example though - > In my view I have this , with the html and code between - > <% content_for ''postform'' do -%> > <% end-%> > > then in my layout i just decide where that goes and put the > @content_for_postform > > Hope this helps and is relevant.According to the documentation, your call to @content_for_postform is deprecated. It says that the preferred way now is to use <%= yield :postform %>. -- James --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---