i am trying to query a table and return a value if the conditions are met.
schedule model
class Schedule < ActiveRecord::Base
belongs_to :result
attr_accessible :result_id
end
results model
class Result < ActiveRecord::Base
has_one :schedule
attr_accessible :against, :for, :schedule_id
end
schedules.haml
- if schedule.result
Result
- else
No Result
all im getting is No Result, even though i know there is results loaded for the scheduling id
any help would be great thanks
Take a look at this site:
http://rubyquicktips.com/post/3096503536/how-to-check-if-objects-or-relations-exist
You may want to try something like
schedule.result.any?
Also, try:
raise schedule.result.to_yaml
to see exactly what is returned by this statement