我是一个新的 Rails 开发人员,他正在创建一个创建以下问题的应用程序:
Routing Error
No route matches {:action=>"show", :controller=>"recipes", :username=>#<Recipe id: 42, name: "Curried Chicken Sandwich", yield: "4 Servings", description: "Burgers aren't the only grilled things we want to e...", created_at: "2013-06-27 18:49:42", updated_at: "2013-06-27 18:49:42", duration: "", author: nil, url: nil, user: 3, image: "curried-chicken-sandwich-646.jpg", user_recipe_id: nil>}
我的 routes.rb 看起来像这样:
match "/:username" => "recipes#index"
scope ':username' do
resources :recipes
end
我的控制器索引如下所示:
def index
if params[:tag]
@recipes = Recipe.tagged_with(params[:tag]).where(:user => current_user.id).paginate(:page => params[:page], :per_page => 45)
else
@user = User.find_by_username params[:username]
@search = Recipe.search do |query|
query.fulltext params[:search]
query.with(:user, @user.id)
query.paginate(:page => params[:page] || 1, :per_page => 20)
end
@recipes = @search.results
respond_to do |format|
format.html # index.html.erb
format.json { render json: @recipes }
end
end
end
我的控制器显示如下所示:
def show
@user = User.find_by_username params[:username]
@recipe = Recipe.where(:user_recipe_id => params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @recipe }
end
end
我的索引视图:
<% if not @recipes.any? %>
No Recipes
<% else%>
<% @recipes.each do |recipe| %>
<h3><%= link_to recipe.name, recipe %></h3>
<% end %>
为什么会这样?显示动作在那里,但在错误中它说它没有。
感谢所有帮助