Created
September 20, 2011 21:55
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/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