This code is provided as an example in for use with devise and OmniAuth, it works in my project.
class User < ActiveRecord::Base
def self.new_with_session(params, session)
super.tap do |user|
if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
user.email = data["email"] if user.email.blank?
end
end
end
end
I don't know why it's a single equals sign as apposed to a double equals sign, which I thought was necessary for if
-statements. My IDE "intelliJ IDEA" agrees with my concerns.
The only necessary thing for an
if
statement to be valid is a boolean expression. In this case, since=
returns the result of the assignment, what's actually being tested is the falsiness ofsession["devise.facebook_data"]
.IntelliJ has a good point to lodge a complaint about code like this, as it's difficult to read without knowing a thing or two about Ruby. A recommendation would be to move that to an explicit assignment statement instead. This has the added benefit of DRYing up a reference to it twice.