- ruby 1.9.2p290
- рельсы 3.1.1
В основном у меня есть две модели: CHEFS и RECIPES.
class Chef < ActiveRecord::Base
has_many :recipes
end
class Recipe < ActiveRecord::Base
belongs_to :chef
end
Иследующие маршруты:
resources :recipes
resources :chefs do
# list of recipes from chef
resources :recipes, :to => 'recipes#index_chef'
end
При этом у меня есть URL-адреса (именно то, что я хочу):
- / recipes - список рецептов
- / chefs / имя пользователя / рецепты - список рецептов шеф-повара
- / chefs / - список поваров
- / chefs / username - профиль шеф-повара
RecipesController:
def index
@chef = Chef.find_by_username(params[:chef_id])
@recipes = Recipe.where({ :status_id => 1 }).order("id desc").page(params[:page]).per(9)
end
def index_chef
@chef = Chef.find_by_username(params[:chef_id])
@recipes = @chef.recipes.where(:status_id => 1).order("id desc").page(params[:page]).per(9)
end
Мои рецепты index просмотр:
<%= link_to recipe.chef.username.capitalize, @chef %>
В http://3001/chefs/username/recipes У меня есть правильная ссылка на профиль Chef.
Но в http://3001/recipes У меня неправильная ссылка.
Что я делаю не так