Stephen M. wrote in post #1035762:> I find in my controllers that I often want to respond to two types of
> request for html in the same action:
>
> 1) A full page request in which the whole page should be rendered
> 2) A request in which a partial should be rendered without the whole
> layout
>
> I have handled this by passing a parameter in the url to indicate which
> one to return but that feels ugly and I wonder if there are better ways?
There are a few possibilities.
Say you wanted a standard products page and a partial to use on the
welcome page for displaying the top selling products:
1. Use a custom action on a single controller.
example.com/products
example.com/products/top_selling
2. Use separate controllers. There nothing to say that models and
controllers must exists in a one-to-one relationship. You can have as
many controllers as you want for a single model.
example.com/products
example.com/top_selling_products
products_controller.rb
top_selling_products_controller.rb
3. Use separate formats. This is a good option in cases where you want
multiple HTML representations for a single resource. Say for example,
one for desktop browsers and one for mobile browsers.
example.com/orders
example.com/orders.iphone
example.com/orders.mobile
--
Posted via 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
groups.google.com/group/rubyonrails-talk?hl=en.