Reputation: 1173
I'm a new rails developer who's creating an application that creates the following issue:
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>}
My routes.rb looks like this:
match "/:username" => "recipes#index"
scope ':username' do
resources :recipes
end
My controller index looks like:
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
and my controller show looks like this:
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
My index view:
<% if not @recipes.any? %>
No Recipes
<% else%>
<% @recipes.each do |recipe| %>
<h3><%= link_to recipe.name, recipe %></h3>
<% end %>
Why does this happen? The show action is there, but in the error it says it doesn't.
thanks for all help
Upvotes: 0
Views: 92
Reputation: 11821
<%= link_to recipe.name, recipe_path(username: @user.username, id: recipe.id) %>
Upvotes: 3