所以我是RoR的新手,我似乎无法做出选择的地方。 这些是以下类:
型号:
class List < ActiveRecord::Base has_many :list_categorization has_many :category, :through => :list_categorization end class ListCategorization < ActiveRecord::Base attr_accessible :category_id, :list_id belongs_to :category belongs_to :list end class Category < ActiveRecord::Base attr_accessible :name has_many :list_categorizations has_many :lists, :through => :list_categorizations end我要做的是选择一个给定类别的列表。 我尝试使用以下代码在list_controler中对此进行简化版本:
class ListsController < ApplicationController @lists = List.where("category.id = ?", 2) end end并通过以下观点:
<ul class="lists"> <%= render @lists%> </ul>然后出现以下错误:
列表中的ActiveRecord :: StatementInvalid#index_where
SQLite3 :: SQLException:没有这样的列:category.id:SELECT“lists”。* FROM“lists”WHERE(category.id = 2)ORDER BY lists.created_at DESC
我究竟做错了什么? 谢谢和最好的问候。
So I'm new to RoR and i can't seem to do a select where statment. These are the following classes:
The models:
class List < ActiveRecord::Base has_many :list_categorization has_many :category, :through => :list_categorization end class ListCategorization < ActiveRecord::Base attr_accessible :category_id, :list_id belongs_to :category belongs_to :list end class Category < ActiveRecord::Base attr_accessible :name has_many :list_categorizations has_many :lists, :through => :list_categorizations endAnd what i'm trying to do is to select a list with a given category. I tried to do a simplified version of this in the list_controler with the following code:
class ListsController < ApplicationController @lists = List.where("category.id = ?", 2) end endAnd with the following view:
<ul class="lists"> <%= render @lists%> </ul>Then the following error apears:
ActiveRecord::StatementInvalid in Lists#index_where
SQLite3::SQLException: no such column: category.id: SELECT "lists".* FROM "lists" WHERE (category.id = 2) ORDER BY lists.created_at DESC
What am I doing wrong? Thanks and best regards.
最满意答案
@lists = Category.find(2).lists @lists = Category.find(2).lists更多推荐
发布评论