Rails 3 overseers NameError (unsealed cast `ranger '):

here's how it should work: I sign up to the admin panel, go to cars / new and fill in the fields, click "Create" and I have to have a new car in my list. www.autozeep.com

the fact is that it goes fine, until I press the Create button to create a new car, the server logs show this:

NameError (uncaught throw `warden'): app/controllers/application_controller.rb:9:in `login_required' app/middleware/flash_session_cookie_middleware.rb:17:in `call' 

in development mode, this works fine, on a server in production mode it is not, this is the same code, nothing has changed. for more server logs: http://pastie.org/3028350

 application_controller class ApplicationController < ActionController::Base protect_from_forgery # filter def login_required return true if authenticated? warden.authenticate! end 

users_controller: http://pastie.org/3028586

I can edit the car, it works fine, so the update and editing functions from cars_controller are fine, I checked new ones and create functions from cars_controller, but I couldn’t stop anything, which would give me an idea of ​​what was going on, Cars_controller: http: //pastie.org/3028452

Please help, I already have this application running, and the client is waiting for this problem to be resolved. Thank you very much.

EDIT

 NameError in CarsController#create uncaught throw `warden' Rails.root: /u/apps/zeepauto/releases/20111123173432 Application Trace | Framework Trace | Full Trace app/controllers/application_controller.rb:9:in `login_required' app/middleware/flash_session_cookie_middleware.rb:17:in `call' ENV DUMP ... .... rack.url_scheme: "http" rack.version: [1, 0] warden: Warden::Proxy:-621456458 @config={:default_strategies=>{:_all=>[:database]}, :failure_app=>UsersController, :default_scope=>:default, :scope_defaults=>{}, :intercept_401=>true} warden.options: {:attempted_path=>"/cars", :action=>"unauthenticated"} 

I get these errors only when I add a new car, I can edit cars, news, contacts. everything except cars.

SOLVED PROBLEM

This problem was caused by some jquery library, I use dynamic_form in this form, so when I select the name of the car in the next select_box, only the models for the selected car are displayed. Having examined the problem (with my teacher, I would not have thought about it myself), we see that when I select a car, a process called “dynamic_carmodels” is started in the logs to update the list of wireframes, and also at that moment the session key is changed by another one, usually, if the session key changes, the session that I started when I logged in is no longer valid, and therefore I get a "no check error". I still don’t know what exactly caused the jquery problem, but in the end, I decided that this was not due to the configuration of the boss.

+4
source share
1 answer

Well, I will explain to you why this exception happens very carefully, but I cannot fix it for you.

Warden protects your application with a catch (: warden) block, you can see this in:

 # Invoke the application guarding for throw :warden. # If this is downstream from another warden instance, don't do anything. # :api: private def call(env) # :nodoc: return @app.call(env) if env['warden'] && env['warden'].manager != self env['warden'] = Proxy.new(env, self) result = catch(:warden) do @app.call(env) end 

Your application is called in @ app.call (env), and if your application drops (: warden), it hits. here's how the cast, trap works, here's an example:

 def authenticate!() throw :warden end catch(:warden) do puts "Calling authenticate!" authenticate!() end puts "Succesfully called authenticate!" #outside of catch(:) guard authenticate!() puts "this never gets executed" 

If I did this, he would do:

  ruby exc.rb Calling authenticate! Succesfully called authenticate! exc.rb:2:in `throw': uncaught throw :warden (ArgumentError) from exc.rb:2:in `initialize!' from exc.rb:12:in `<main>' 

As you can see, the second time I called authentication! I was outside the catch block (: the caretaker), so when I drop: the authorities did not have a lock to catch it, an exception arose.

This is what happens to you, look at warden#authenticate! :

 def authenticate!(*args) user, opts = _perform_authentication(*args) throw(:warden, opts) unless user user end 

See cast (: ranger, choice)? If this throw is outside the catch (: warden) lock, the exception is thrown. The keeper must guard your entire application in a catch block so you can drop: the ranger at any time. But for some reason this does not happen on zeepauto.

Your problem is that the warden is not configured correctly (no config/initializers/warden.rb ) and call (env) , so the protection of your street (: guard) is never installed.

Your answer here: https://github.com/hassox/warden/wiki/Setup

Just work yourself through the setup. You can test your development environment by dropping: a caretaker at any time. Just write a test, for example:

 it "warden should catch the throw :warden at any point" do throw(:warden) end 

If you want to get this thing faster, just run a pro account on railscasts.com and see: http://railscasts.com/episodes/305-authentication-with-warden for the episode to guide you through the setup.

+10
source

Source: https://habr.com/ru/post/1386779/


All Articles