0

has_many リレーションシップの find メソッドにアクセスしようとすると、非常に奇妙なエラーが発生します。

構文的に何が間違っていますか?

# Instructor model
class Instructor < ActiveRecord::Base
  has_many :events
end

# Event model
class Event < ActiveRecord::Base
  belongs_to :instructor
end

# Controller snip-it
i = Instructor.first
conditions = [ :start_time => params[:start]..params[:end], :submitted => true ]
@events = i.events.find(:all, :conditions => conditions)

# Error message
# NoMethodError (undefined method `%' for {:start_time=>"1283140800".."1286769600", :submitted=>true}:Hash):
4

1 に答える 1

3

この行:

conditions = [ :start_time => params[:start]..params[:end], :submitted => true ]

読むべき:

conditions = { :start_time => params[:start]..params[:end], :submitted => true }

単一のハッシュではなく、ハッシュを含む配列を作成していました。

于 2010-09-07T22:17:56.280 に答える