1
내 게시물을 필터링하지만 인수 오류의 잘못된 번호 얻기 위해 노력하고Rails의 고급 쿼리에서 잘못된 개수의 인수 오류가 발생하는 이유는 무엇입니까?
임 조건 여기
if current_user.courses.any? {|h| h[:name] == post.course.name}
의 기반으로 그들을 필터링하려고 (1 주어는 0 예상) 내 컨트롤러 액션이다 인덱스 여기
def index
@posts = Post.all(:joins => :course, :conditions => "courses.name in (#{@user.courses.map(&:name).join(',')})",:order => "posts.created_at DESC")
end
내 모델은
class Post < ActiveRecord::Base
belongs_to :user
belongs_to :course
has_many :comments
end
class Course < ActiveRecord::Base
belongs_to :user
has_many :posts
belongs_to :major
end
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :courses
belongs_to :major
has_many :posts
has_many :comments
accepts_nested_attributes_for :courses, reject_if: :all_blank, allow_destroy: true
end
감사합니다.