我想要使用此功能從mongoid:傳遞屬性Mongoid update_attributes方法()
person.update_attributes(first_name: "Jean", last_name: "Zorg")
但我想從另一個變量的所有屬性通過。我怎麼做?
編輯:謝謝大家的回覆。我是新來的紅寶石,所以起初我以爲我只是犯了一個愚蠢的錯誤。該缺陷是在一個完全不同的地方,正確的代碼,爲您的享受:
def twitter
# Scenarios:
# 1. Player is already signed in with his fb account:
# we link the accounts and update the information.
# 2. Player is new: we create the account.
# 3. Player is old: we update the player's information.
# login with a safe write.
puts "twitter"
twitter_details = {
twitter_name: env["omniauth.auth"]['user_info']['name'],
twitter_nick: env["omniauth.auth"]['user_info']['nickname'],
twitter_uid: env["omniauth.auth"]['uid']
}
if player_signed_in?
@player = Player.find(current_player['_id'])
else
@player = Player.first(conditions: {twitter_uid: env['omniauth.auth']['uid']})
end
if @player.nil?
@player = Player.create!(twitter_details)
else
@player.update_attributes(twitter_details)
end
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Twitter"
sign_in_and_redirect @player, :event => :authentication
end
您在哈希擁有姓氏和名字? –
是的(我有他們在散列) – CamelCamelCamel
不理解這一點,無論是。如果你在一個變量中有一個哈希集,你可以將這個哈希函數傳遞給函數...... – WattsInABox