Here it goes....

A layout is like the container for the content(.. view) relating to
your actions.  When an action is called, the action renders its view.
For example, the person controllers index action will look for app/
views/person/index.html.erb.  It also looks for the layout it should
render the view in.  You can define the layout to use either in the
controller (layout 'application' in your case) or put in in
application.rb, which will then define a global default layout.

You've got the right idea with the erb you posted. You can render
partials in layouts, but for the action to render it's view in the
layout, you need to put <%= yield %>.  The entire contents of the
actions's view will get rendered there.

Your layout, application.html.erb should be residing in the app/views/
layout directory.  You should add "layout 'application'" to your
controller, add <%= yield %> to the layout, create views for your
actions and try it out.  Your views should render inside your layout.

I hope that gives you some idea of how views and layouts interact.

- John

On Dec 23, 8:38 am, sa 125 <[email protected]> wrote:
> Hello - very new to rails and MVC, I'm trying to figure out how
> layouts/partials co-exist. My basic layout (application.html.erb) looks
> like this:
>
> <body>
>   <div id="wrapper">
>     <%= render :partial => "main/header" %>
>     <div id="content">
>       <%= render => :partial => "main/menu" %>
>       <%= render => :partial => @partial %>
>     </div>
>   </div>
> </body>
>
> and my MainController is:
>
> class MainController
>
>   def index
>     @partial = "main/home"
>   end
>
> end
>
> Now, I found that I have to create an index.html.erb file that's
> identical to the application.html.erb file, or nothing works (neither
> can exist without the other). I'm trying to understand what I'm doing
> wrong -- obviously I need some index action in my controller, but I'd
> like to just maintain one layout file and nothing else.. I'm obviously
> missing something big here, so any clarifications will be great :)
> --
> Posted viahttp://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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to