-
-
Save ch1ago/1917871 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
belongs_to :gift | |
belongs_to :user |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% @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 %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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