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
ありがとう!