为什么我在配方视图中看到来自Recipe模型的每条记录的activerecord对象ID?在索引操作的底部,我看到了:
#<Recipe:0x1056c1d98>#<Recipe:0x1056c1cd0>
模特:
class Recipe < ActiveRecord::Base
attr_accessible :name, :description, :quick_facts, :ingredients, :instructions, :user_id, :hashtag, :image
mount_uploader :image, ImageUploader
end
观点:
.section-header The Recipes as seen on: #DriscollsMoments
= recipes.each do |recipe|
#recipe
#image-container
= link_to(image_tag(recipe.image_url, :width => 200, :height => 100, :border => 0), recipe_path(recipe.id))
#information
= link_to recipe.name, recipe_path(recipe.id), :class => 'recipe-name'
= link_to 'view recipe & tweet', recipe_path(recipe.id), :class => 'view-recipe'
.clear
%p= recipe.description
.clear
控制器:
class RecipesController < ApplicationController
def index
@recipes = Recipe.find(:all)
end
def show
end
end
这个问题对于这个模型来说是独一无二的 - 它在我的应用程序中的任何其他位置都没有。我尝试禁用carrierwave以查看是否有任何影响,它似乎没有任何区别。我有两个recipes_controllers,一个是管理员控制器,但这也不应该是问题。我知道这很明显。有什么想法吗?
答案 0 :(得分:4)
在您看来,请替换为:
= recipes.each do |recipe|
用这个:
- recipes.each do |recipe|
=
导致在执行循环后输出recipes
数组的内容。
答案 1 :(得分:2)
我相信这一行:
= recipes.each do |recipe|
应该是:
- recipes.each do |recipe|