Je veux utiliser cette fonction de MongoId:Passing attribue à MongoId update_attributes()
person.update_attributes(first_name: "Jean", last_name: "Zorg")
Mais je veux passer dans tous les attributs d'une autre variable. Comment je fais ça?
Editer: Merci à tous pour votre réponse. Je suis nouveau à ruby donc au début je pensais que je viens de faire une erreur stupide avec ça. Le bogue a été dans un endroit complètement différent, le bon code, pour votre plaisir:
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
Vous avez les noms et prénoms dans un Hash? –
Oui (je les ai dans un hachage) – CamelCamelCamel
Ne comprenant pas cela non plus. Si vous avez un hash défini dans une variable, vous pouvez juste passer ce hash dans la fonction ... – WattsInABox