-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
Error appear when current_user is active.
View (pages/index):
<% if current_user %>
Signed in as <%= current_user.name %>!
<%= link_to 'Sign out', signout_path %>
<% end %>
Application controller:
class ApplicationController < ActionController::Base
- Prevent CSRF attacks by raising an exception.
- For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
private
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
helper_method :current_user
end
User model:
class User
include Mongoid::Document
include Mongoid::Timestamps
field :provider, type: String
field :uid, type: String
field :name, type: String
def self.from_omniauth(auth)
where(auth.slice("provider", "uid")).first || create_from_omniauth(auth)
end
def self.create_from_omniauth(auth)
create! do |user|
user.provider = auth["provider"]
user.uid = auth["uid"]
user.name = auth["extra"]["raw_info"]["name"]
end
end
end
Error:
The operation: #<Moped::Protocol::Query
@length=90
@request_id=19
@response_to=0
@op_code=2004
@flags=[]
@full_collection_name="monkeywork_development.users"
@skip=0
@limit=0
@selector={"_id"=>{"$oid"=>BSON::ObjectId('54e5d31c5365623549000000')}}
@fields=nil>
failed with error 17287: "Can't canonicalize query: BadValue unknown operator: $oid"