1
我想篩選我的帖子卻得到了一個錯誤的號碼參數錯誤的(因爲1,預計0)爲什麼我在Rails中的高級查詢中得到錯誤的參數數量錯誤?
我試着基於關閉狀態
if current_user.courses.any? {|h| h[:name] == post.course.name}
這裏來過濾他們是我的控制器行動對於指數
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
謝謝!