On Aug 25, 10:10 pm, gregory barborini [email protected]
I’m working on a website listing recipes. I need 2 views :
- the first will be my “Home” page with the last 6 recipes and much
- the second is a listing of all the recipes sorted by alphabetical
I’d like to find a Restful solution…
But how can i manage :
- 1 controller with 2 methods like show and show_last_recipes ?( … I
don’t think it’s very Restful)
I agree Custom actions are usually a last resort for me.
- 2 views with 1 controller and depending on a “display” variable my
controller will choose between the 2 views…
I’m not very happy with those 2 solutions.
Do you have any ideas ? Thanks
First, it’s a myth that you’re not allowed to have a “home” controller
to serve as your home page. This controller can render as many
resources, in whatever fashion, and it deems appropriate. The home
page is a kind of resource unto itself, and can be treated restfully.
With that in mind, here’s one way to proceed:
Add a HomeController, with an index action, to serve as your home
map.root :controller => ‘home’
@recipes = Recipe.find(:all, :limit => 6, :order => ‘id desc’)
Your RecipesController can be fully RESTful as you would expect, using
map.resources :recipes, etc.
If you’re concerned about redundant code in your views, first write
your views and see what happens. If they are indeed duplicating code,
you can just factor out the reusable stuff into partials that you can
share among controllers.
Hope this helps…?
REST with Rails: Do cool things with Rails! For beginning Rails
developers or those just new to REST.
Oct 4, 2008, Austin, TX, $295. Use discount code “PWRRGG” for 10%