Skip to content

Instantly share code, notes, and snippets.

@ch1ago
Created February 3, 2012 17:33
Show Gist options
  • Save ch1ago/1731302 to your computer and use it in GitHub Desktop.
Save ch1ago/1731302 to your computer and use it in GitHub Desktop.
<jarr0dsz> im having a @group.participants.order(:id).offset(0).limit(1).first that returns a participant object i checked with .inspect but how do i get an attribute from that?
first_participant = @group.participants.order("id").select("name").first || :no_participant_for_this_group
if first_participant == :no_participant_for_this_group
puts first_participant.name
else
puts first_participant.name
end
--
even if you don't put that if statement to validate...
and if there are no participants, it will generate an exception
with the name :no_participant_for_this_group on the log file,
witch will make your life easier to search for that code ;)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment