How to access "extra" Hashie in omniauth-facebook callback - ruby-on-rails

In a Rails app I had the following code updating the user's profile from their Facebook profile
self.update_attributes( :location => request.env["omniauth.auth"].extra.raw_info.location.name )
I'm in the process of updating Rail and gems, and now this line is failing.
NoMethodError (undefined method `name' for nil:NilClass):
Looking at the output, I see
...
extra: !map:Hashie::Mash
raw_info: !map:Hashie::Mash
...
How can I access attributes within this Hashie?

Related

Rails Rich Text (Trix) return NoMethodError: undefined method `render' for nil:NilClass

When I try to run a rake task, Trix return this error NoMethodError: undefined method "render" for nil:NilClass in this file:
/bundle/ruby/2.7.0/gems/actiontext-6.0.0/lib/action_text/content.rb:91:in `to_rendered_html_with_layout'
/bundle/ruby/2.7.0/gems/actiontext-6.0.0/lib/action_text/content.rb:95:in `to_s'
/bundle/ruby/2.7.0/gems/actiontext-6.0.0/app/models/action_text/rich_text.rb:12:in `to_s'
In console, in development environment, when I request a model instance and get model.content works. But, when I request this in rake task (paused by byebug or printing with puts) I get this error: *Error in evaluation*.
In normal runnig everything is working, same for rails console. This error shows only in rake task, even though I just fetching the model from the database and trying to call model.content.
model.content is not blank.

Rails 5, Ckeditor and Paperclip error when loading and searching for images

I'm using rails 5 api and am trying to implement a ckeditor wysiwyg in a form using angularjs 1. I'm using rails 5.1.4, ckeditor 4.2 and paperclip 5.1.0.
I have followed the directions from here: https://github.com/galetahub/ckeditor for the gem implementation and have run the generator:
rails generate ckeditor:install --orm=active_record --backend=paperclip
When trying to "Browse Server" or upload an image to the server through the ckeditor I am performing the following Get request:
Started GET "/ckeditor/pictures?CKEditor=js-ckeditor&CKEditorFuncNum=1&langCode=en" for 172.23.0.1 at 2017-10-24 01:59:04 +0000
And I then get the following error:
ActionController::RoutingError (undefined method `layout' for Ckeditor::ApplicationController:Class):
ckeditor (4.2.4) app/controllers/ckeditor/application_controller.rb:2:in `<class:ApplicationController>'
ckeditor (4.2.4) app/controllers/ckeditor/application_controller.rb:1:in `<top (required)>'
This is the controller where the error is coming from: https://github.com/galetahub/ckeditor/blob/master/app/controllers/ckeditor/application_controller.rb
Edit: Turns out the rails 5 api does not include ActionView::Layouts out of the box, so I added this following to my ApplicationController:
include ::ActionView::Layouts
This took care of the undefined method 'layout'. However, now I have another error coming from the same ckeditor controller after the Get request has been passed to the index action. I am also using devise_token_auth and pundit for authorization and authentication.
Processing by Ckeditor::PicturesController#index as HTML
Parameters: {"CKEditor"=>"js-ckeditor", "CKEditorFuncNum"=>"1", "langCode"=>"en"}
Completed 500 Internal Server Error in 149ms (ActiveRecord: 0.0ms)
NoMethodError (undefined method `ckeditor_authorize!' for #<Ckeditor::PicturesController:0x007f5e7ac7dc30>):
this is the CKeditor Application Controller where you get the error, you should include this code to your question with link to the page
class Ckeditor::ApplicationController < Ckeditor.parent_controller.constantize
layout Ckeditor.controller_layout
before_action :find_asset, only: [:destroy]
before_action :ckeditor_authorize!
before_action :authorize_resource
protected
def respond_with_asset(asset)
asset_response = Ckeditor::AssetResponse.new(asset, request)
if asset.save
render asset_response.success(config.relative_url_root)
else
render asset_response.errors
end
end
end
I don't know why it is not working and I don't have any idea what Ckeditor.controller_layout is.. keep me updated with your progress

ActionController::InvalidAuthenticityToken Error

I have used Devise gem in my rails app. When I click on logout it takes me to an error page that is:
ActionController::InvalidAuthenticityToken in Devise::SessionsController#destroy
ActionController::InvalidAuthenticityToken
Extracted source (around line #181):
def handle_unverified_request
raise ActionController::InvalidAuthenticityToken
end
end
end
On refreshing the same page, it works correctly and user gets logged out.
The error occurred after i run rake db:reset, before it was running fine
How is this caused and how can I fix it?

Rails_admin undefined method `associations' for nil:NilClass

I have these models:
Class A
embeds_many :b
end
Class B
belongs_to :c
end
Class C
end
I'm working with rails_admin and mongoid. In admin, when I try to retrieve the list of C records when I'm creating an A instance I'm getting this error:
This only happens on production envirnment not in development
NoMethodError (undefined method `associations' for nil:NilClass):
/home/pablo/.rvm/gems/ruby-2.3.0#mh-backend/bundler/gems/rails_admin-355dc80f8a20/lib/rails_admin/adapters/mongoid/abstract_object.rb:10:in `initialize'
/home/pablo/.rvm/gems/ruby-2.3.0#mh-backend/bundler/gems/rails_admin-355dc80f8a20/lib/rails_admin/adapters/mongoid.rb:24:in `new'
/home/pablo/.rvm/gems/ruby-2.3.0#mh-backend/bundler/gems/rails_admin-355dc80f8a20/lib/rails_admin/adapters/mongoid.rb:24:in `get'
/home/pablo/.rvm/gems/ruby-2.3.0#mh-backend/bundler/gems/rails_admin-355dc80f8a20/app/controllers/rails_admin/main_controller.rb:138:in `get_association_scope_from_params'
Taking a look at rails_admin code we can see that piece of code in mongoid.rb file.
def get(id)
AbstractObject.new(model.find(id))
rescue => e
raise e if %w(
Mongoid::Errors::DocumentNotFound
Mongoid::Errors::InvalidFind
Moped::Errors::InvalidObjectId
BSON::InvalidObjectId
).exclude?(e.class.to_s)
end
If we pay attention at this code we can see that model.find(id) must produce a Mongoid::Errors::DocumentNotFound if document doesn't exists by default.
However, in mongoid you can avoid the raise of this error with raise_not_found_error: true in mongo config file, this produce the undefined method of nil class.
Tracking issue on github

configure warden rails

I started my rails app and suddenly got the following error
/.rvm/gems/ruby-1.9.3-p194/gems/devise-2.1.2/lib/devise.rb:406:in `configure_warden!': undefined method `failure_app=' for nil:NilClass (NoMethodError)
devise.rb line 406 has:
warden_config.failure_app = Devise::Delegator.new
I cannot figure out the problem, how do i go about this?

Resources