Rails route, show all elements on the same page

Posted by Igor Oliveira Antonio on Stack Overflow See other posts from Stack Overflow or by Igor Oliveira Antonio
Published on 2014-06-09T09:13:26Z Indexed on 2014/06/09 9:24 UTC
Read the original article Hit count: 283

I need to show all my elements on the same page. In routes:

  namespace :nourishment do
   resources :diets do
     resources :nourishment_meals, :controller => 'meals'
     get 'nourishment_meals/show_all_meals' => 'meals#show_all_meals', as: "show_all_meals"
   end
  end

which will generate:

nourishment_diet_nourishment_meals_path  GET     /nourishment/diets/:diet_id/nourishment_meals(.:format)     nourishment/meals#index
POST     /nourishment/diets/:diet_id/nourishment_meals(.:format)     nourishment/meals#create
new_nourishment_diet_nourishment_meal_path   GET     /nourishment/diets/:diet_id/nourishment_meals/new(.:format)     nourishment/meals#new
edit_nourishment_diet_nourishment_meal_path  GET     /nourishment/diets/:diet_id/nourishment_meals/:id/edit(.:format)    nourishment/meals#edit
nourishment_diet_nourishment_meal_path   GET     /nourishment/diets/:diet_id/nourishment_meals/:id(.:format)     nourishment/meals#show
PATCH    /nourishment/diets/:diet_id/nourishment_meals/:id(.:format)     nourishment/meals#update
PUT  /nourishment/diets/:diet_id/nourishment_meals/:id(.:format)     nourishment/meals#update
DELETE   /nourishment/diets/:diet_id/nourishment_meals/:id(.:format)     nourishment/meals#destroy


[**THIS**]
    nourishment_diet_show_all_meals_path     GET     /nourishment/diets/:diet_id/nourishment_meals/show_all_meals(.:format)  nourishment/meals#show_all_meals

The problem, when I do this:

<%= link_to "Show all meals", nourishment_diet_show_all_meals_path, :class=>"button green" %>

This error raise:

Problem:


Document(s) not found for class NourishmentMeal with id(s) show_all.
Summary:
  When calling NourishmentMeal.find with an id or array of ids, each parameter must match a document 

Can someone help me?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about custom-routes