Skip to content

Instantly share code, notes, and snippets.

@th1agoalmeida
Forked from anonymous/gist:1917840
Created February 26, 2012 17:30
Show Gist options
  • Save th1agoalmeida/1917871 to your computer and use it in GitHub Desktop.
Save th1agoalmeida/1917871 to your computer and use it in GitHub Desktop.
belongs_to :gift
belongs_to :user
#I don't think you should nest this.
class Users::MygiftsController < ApplicationController
before_filter :authenticate_user!
def index
# you should not do this, every single request of your app will ALWAYS spend
# 300ms more, because you need to request facebook API all the time.
# you should cache all the info you want in the database
# and update it when the user logs in.
@myself = FbGraph::User.me(session[:omniauth]["credentials"]["token"]).fetch()
# see how you can do it with a model named Facebook :)
# @facebook = Facebook.where(:user_id=>current_user.id).first
# or...
# @facebook = current_user.facebook
end
end
<% @myself.gift_users.each do |gift_user| %>
<p>gift: <%= gift_user.gift.name %></p>
<p>original price: <%= gift_user.gift.original_price %></p>
<p>id: <%= gift_user.id %></p>
<p>sender: <%= gift_user.user.name %></p>
<p>status: <%= giftuser.status %></p>
<% end %>
def name
"#{first_name} #{last_name}"
end
has_many gifts_users, :foreign_key => 'receiver_id'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment