0

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

Bohdan
  • 8,298
  • 6
  • 41
  • 51
Boss Nass
  • 3,384
  • 9
  • 48
  • 90
  • Is the above sample from your schedules.haml formatted correctly? HAML relies on indentation. The "- else" should be aligned with the "- if". – steakchaser Jul 30 '12 at 14:29
  • yes its formatted correctly, all im getting is the No Result for everyone item which isnt correct – Boss Nass Jul 30 '12 at 14:30

1 Answers1

1

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

Sabar
  • 478
  • 2
  • 20