I'm getting a very odd error when I attempt to access the find method of a has_many relationship.
What am I doing开发者_JS百科 wrong syntactically?
# 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):
This line:
conditions = [ :start_time => params[:start]..params[:end], :submitted => true ]
Should read:
conditions = { :start_time => params[:start]..params[:end], :submitted => true }
You were creating an array with a hash in it instead of a single hash.
精彩评论