On Mar 4, 2008, at 8:18 AM, Joel S. wrote:
public folder don’t invoke Rails, so you won’t get to share the
Ok I am with you so far. One question I have though is how to call
multiple items into a single page - this might be a different topic
all
together?
Say my index page is suppose to have its main content in the center, a
username login / password option on the top, and cateogries on the top
and the left. Each of the just mentioned have their own controllers
and
models since they are all their own tables in the db.
(I’m jumping into the middle of this thread so apologies if I’m
repeating something already said.)
Your implicit assumption that each table must be handled by its own
controller is false.
The login option can be a partial that is conditionally rendered
(assuming the conventions of acts_as_authenticated):
<% if logged_in? -%>
<%= current_user.name %>
<% else -%>
<%= render :partial => 'login' %>
<% end -%>
For the categories, the controller sets up an instance variable by
invoking the model:
@top_categories = Category.for_top
@side_categories= Category.for_side(:kind => ‘interesting’)
which the layout or the view can render as a partial
<%= render :partial => ‘top_categories’, :object => @top_categories %>
<%= render :partial => ‘side_category’, :collection =>
@side_categories %>
If these partials are used by more than one controller, you can place
them all into an app/views/shared/ directory or refer to them with
their native controller’s name:
<%= render :partial => ‘account/login’ %>
So how do I include it all together? I was told in order to have the
visual layout in my front end to put the layout in the layouts folder
for say the index page (or the gloabl layout). Well thats peachy but I
am not sure how to call all of the different models into one page
using
the
In the layout:
<%= yield :this_thing %>
In your view:
<% content_for :this_thing do %>
stuff
<%= link_to ‘wow’, wow_path, :class => ‘amazing’ %>
<% end %>
The view is actually rendered first and then the layout is found and
wrapped around it even though you tend to think of it the other way
around.
Should I be thinking of this as having a layout for each controller
then
calling all of those seperate layouts into one?
You certainly can have a different layout per controller (which is the
default actually if you follow the naming conventions), but you can
also specify a layout directly:
render :layout => 'alternate'
render :action => 'edit', :layout => 'admin'
-Rob
Rob B. http://agileconsultingllc.com
[email protected]