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_sessi
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 of session["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.
class User < ActiveRecord::Base
def self.new_with_session(params, session)
super.tap do |user|
data = session["devise.facebook_data"]
if data && data["extra"]["raw_info"]
user.email = data["email"] if user.email.blank?
end
end
end
end