views:

16

answers:

1

I'm getting a very odd error when I attempt to access the find method of a has_many relationship.

What am I doing 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):
+3  A: 

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.

wuputah
Oh. Thanks. You rock!
Sukima