Skip to content

Instantly share code, notes, and snippets.

@safarista
Created September 20, 2011 21:55
Show Gist options
  • Save safarista/1230533 to your computer and use it in GitHub Desktop.
Save safarista/1230533 to your computer and use it in GitHub Desktop.
Trying to find recipes based on the user from the url, maybe wrong but its same as using current_user.id. Also why the "Show" path is not working though the url is. Rails 3.1.0
#/app/views/recipes/index.html.erb
#ERROR: undefined method `each' for #<Recipe:0x00000102e88a20>
<% @recipes.each do |recipe| %>
<tr>
<td>0001</td>
<td><%= recipe.name %></td>
<td><%= recipe.status %></td>
<td><%= recipe.due_on.strftime('%d %B') %></td>
<td><%= link_to "Show", user_recipe_path(recipe) %></td>
</tr>
<% end %>
#END of index view
#/app/controllers/recipes
class RecipesController < ApplicationController
# GET /recipes
# GET /recipes.json
def index
@recipes = Recipe.find_by_user_id
respond_to do |format|
format.html # index.html.erb
format.json { render json: @recipes }
end
end
end
#URLs
http://localhost:3000/users/1/recipes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment