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?
Related
I'm running ActiveStorage direct upload on a form and when the form gets submitted it uploads to S3. I have a check in a service object that checks to see if the file is too large even after getting past some javascript that checks the size. If it is, the file is deleted off S3 and I remove the ActiveStorage::Blob from my database (for technical constraints). When I run the following code:
def blob
#blob ||= ActiveStorage::Blob.find_signed(signed_id) unless signed_id.blank?
rescue StandardError => error
# Handle error
end
if a user refreshes the page and the form is resubmitted with the signed_int ActiveRecord::RecordNotFound is still raised to the controller and fails on the memoization line.
What could cause a rescue on StandardError to not be caught?
Edit: Here's the stack trace
ActiveRecord::RecordNotFound - Couldn't find ActiveStorage::Blob with 'id'=80:
app/services/contact_us_form_manager.rb:76:in `blob'
app/services/contact_us_form_manager.rb:66:in `check_file_size'
app/services/contact_us_form_manager.rb:37:in `create'
app/controllers/admin/contacts_controller.rb:18:in `create'
app/controllers/application_controller.rb:280:in `set_true_user'
app/controllers/application_controller.rb:262:in `set_current_user'
app/controllers/application_controller.rb:255:in `set_current_client'
app/controllers/application_controller.rb:113:in `assign_time_zone'
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
Had been in the process of getting a Rails Engine upgraded to Rails 5.1 and now in the process of getting the rspec tests back working.
I have a controller, and in that controller I have the following:
module Users
class SessionsController < Devise::SessionsController
skip_before_action :authenticate_user!
skip_before_action :authorize_user!
def create
super
flash[:analytics] = { "data-analytics-form-completed-name" => "#{StewardshipUser.app_slug}/sign-in", "data-analytics-form-completed-type" => "login" }
end
def repopulate_email
(params[:user] && params[:user][:email]) ? params[:user][:email] : ''
end
helper_method :repopulate_email
end
end
If I remove the skip_before_action :authorize_user! the tests run, but not all successfully.
With the line I'm getting the following error:
An error occurred while loading ./spec/validators/rfc_compliant_validator_spec.rb.
Failure/Error: Dummy::Application.initialize!
RuntimeError:
can't modify frozen Array
# /Users/ahcarpenter/.rvm/gems/ruby-2.2.2/gems/railties-5.1.4/lib/rails/engine.rb:579:in `unshift'
# /Users/ahcarpenter/.rvm/gems/ruby-2.2.2/gems/railties-5.1.4/lib/rails/engine.rb:579:in `block in <class:Engine>'
Any thoughts on why the initializer would be breaking down with that line in there?
Additionally, when I had initially gone to reinitialize rspec, I had to comment out that method to get the initializer to run as it was not found any longer for some reason (I don't seem to have bumped any gem versions up that contained that method, but maybe so)
I'm sure you've fixed this by now, but I had this error, I realized that my test database was not initialized properly. I fixed the error by running the following command:
rails db:migrate RAILS_ENV=test
I hope this is helpful for anyone who stumbles across this post.
after update my app to Rails 5 i am struggling with the following error.
I will post a snippet of my rspec test code.
This is my cookies method.
def cookies
request = page.driver.request
ActionDispatch::Cookies::CookieJar.build(request, request.cookies).tap do |jar|
jar.update(
page.driver.browser.rack_mock_session.cookie_jar.to_hash
)
end
end
When i try to call cookies.signed
(byebug) cookies.signed
*** NoMethodError Exception: undefined method `secret_token' for #<Rack::Request:0x007fd9702b3710>
Printscreen of the test error
Thanks
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?