내가 협회사용 협회 PARAMS는
class PostsController < ApplicationController
load_and_authorize_resource
def index
if params[:event_id] then
@event = Event.find(params[:event_id])
if params[:category_id] then
@category = Category.find(params[:category_id])
@posts = Post.where(:event_id => @event.id,
:product => {:category_id => @category.id })
end
end
end
를 통해 액세스 할 PARAMS를 사용하여 컬렉션을 좁힐하려는 나에게
No attribute named 'category_id' exists for table 'product'
는 그러나 열 'CATEGORY_ID이'표 '에 존재하는 오류를 제공합니다 생성물'. 이 오류를 검색해도 아직 도움이되는 내용이 표시되지 않았습니다. 나는 또한 '위임자'를 사용하여 속성에 액세스 가능하게하려고 시도했지만 그 중 하나도 작동하지 않았습니다. 나는 혼란 스럽다.
여기 스키마
입니다create_table "posts", :force => true do |t|
t.float "quantity"
t.datetime "deadline"
t.integer "product_id"
t.integer "event_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "products", :force => true do |t|
t.string "title"
t.text "desc"
t.text "ingredients"
t.float "deposit"
t.float "cost"
t.string "units"
t.float "quantity"
t.float "deadline_hours"
t.boolean "presell_option"
t.integer "user_id"
t.integer "category_id"
t.integer "club_id"
t.datetime "created_at"
t.datetime "updated_at"
end
편집 :
나는 교정합니다 님의 '제품' '제품을'내가이 더 나 퍼즐
SQLite3::SQLException: no such column: products.category_id: SELECT "posts".* FROM "posts" WHERE (("products"."category_id" = 2 AND "posts"."event_id" = 10))
이 관련 오류를 얻을, 스키마에서 상품 테이블에 category_id가 있다고 말합니다.
나는 이것을 수정하려고했는데, 내 편집을보고, 오류에 대한 아이디어가 있습니까? 내가 포함시켜야 할 것이 있습니까? – thejonster
제 답변이 업데이트되었습니다. –
예, 작동합니다. 고맙습니다. 조인이 무엇이고 어디에서 사용해야 하는지를 배워야 할 것 같습니다. – thejonster