Skip to content

Commit

Permalink
use .first method refs codefirst#170
Browse files Browse the repository at this point in the history
  • Loading branch information
shimomura1004 committed Jul 5, 2014
1 parent ddd5d01 commit c4b7d9d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def to_json
end

def profile_for(room_id)
profile = self.user_profiles.where(:room_id => room_id)[0]
profile = self.user_profiles.where(:room_id => room_id).first
{
:name => profile.try(:name) || self.name,
:profile_image_url => profile.try(:profile_image_url) || self.profile_image_url
Expand All @@ -32,7 +32,7 @@ def profile_for(room_id)

def find_or_create_profile_for(room_id)
self.user_profiles ||= []
room = Room.where(:_id => room_id)[0]
room = Room.where(:_id => room_id).first
self.user_profiles.find_or_create_by(:room_id => room._id) unless room.nil?
end

Expand All @@ -42,7 +42,7 @@ def update_profile_for(room_id, new_name, new_icon_url)
end

def delete_profile_for(room_id)
room = Room.where(:_id => room_id)[0]
room = Room.where(:_id => room_id).first
self.user_profiles.where(:room_id => room._id).delete unless room.nil?
end

Expand Down

0 comments on commit c4b7d9d

Please sign in to comment.