I tried to follow the 'Secure Upload' in carrier wave which is a bit confusing because I have customized the file path and all a bit. When I try to run the app, I get 'Cannot read file' error.
Here's the route :
match "/uploads/tobereviewed/:user.:username.downcase/:basename.:extension", :controller => "photos", :action => "uploaded", via: :get
The sotre_dir of uploader :
class SubmitUploader < CarrierWave::Uploader::Base
def store_dir
"uploads/tobereviewed/#{model.user.username.downcase}"
end
carrierwave.rb initializer :
CarrierWave.configure do |config|
config.permissions = 0600
config.directory_permissions = 0700
config.root = Rails.root
end
Photos controller :
def uploaded
file = Submit.first
send_file "#{Rails.root}/uploads/tobereviewed/#{file.user.username.downcase}/#{file.id}"
end
The full error log :
Started GET "/uploaded" for 127.0.0.1 at 2014-11-27 18:19:09 +0530
Processing by PhotosController#uploaded as HTML
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
Submit Load (2.6ms) SELECT "submits".* FROM "submits" ORDER BY "submits"."id" ASC LIMIT 1
User Load (2.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
Sent file /home/pubudu/Projects/istockseller/uploads/tobereviewed/thpubs/36603935 (0.7ms)
Completed 500 Internal Server Error in 54ms
ActionController::MissingFile - Cannot read file /home/pubudu/Projects/istockseller/uploads/tobereviewed/thpubs/36603935:
actionpack (4.2.0.beta4) lib/action_controller/metal/data_streaming.rb:68:in `send_file'
actionpack (4.2.0.beta4) lib/action_controller/metal/instrumentation.rb:49:in `block in send_file'
activesupport (4.2.0.beta4) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0.beta4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0.beta4) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0.beta4) lib/action_controller/metal/instrumentation.rb:47:in `send_file'
() home/pubudu/Projects/istockseller/app/controllers/photos_controller.rb:24:in `uploaded'
actionpack (4.2.0.beta4) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.0.beta4) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0.beta4) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0.beta4) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0.beta4) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0.beta4) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0.beta4) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0.beta4) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0.beta4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0.beta4) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0.beta4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0.beta4) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0.beta4) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0.beta4) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0.beta4) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0.beta4) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0.beta4) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0.beta4) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0.beta4) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0.beta4) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0.beta4) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0.beta4) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0.beta4) lib/action_dispatch/routing/route_set.rb:780:in `call'
omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.0.beta) lib/rack/etag.rb:23:in `call'
rack (1.6.0.beta) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.0.beta) lib/rack/head.rb:13:in `call'
actionpack (4.2.0.beta4) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0.beta4) lib/action_dispatch/middleware/flash.rb:257:in `call'
rack (1.6.0.beta) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.0.beta) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0.beta4) lib/action_dispatch/middleware/cookies.rb:558:in `call'
activerecord (4.2.0.beta4) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0.beta4) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0.beta4) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0.beta4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0.beta4) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0.beta4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0.beta4) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0.beta4) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
better_errors (1.1.0) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (1.1.0) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (1.1.0) lib/better_errors/middleware.rb:56:in `call'
web-console (2.0.0.beta4) lib/action_dispatch/debug_exceptions.rb:18:in `middleware_call'
web-console (2.0.0.beta4) lib/action_dispatch/debug_exceptions.rb:13:in `call'
actionpack (4.2.0.beta4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0.beta4) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0.beta4) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0.beta4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0.beta4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0.beta4) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0.beta4) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.0.beta4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.0.beta) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.0.beta) lib/rack/runtime.rb:17:in `call'
activesupport (4.2.0.beta4) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.0.beta) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0.beta4) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.0.beta) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0.beta4) lib/rails/engine.rb:514:in `call'
railties (4.2.0.beta4) lib/rails/application.rb:161:in `call'
rack (1.6.0.beta) lib/rack/tempfile_reaper.rb:15:in `call'
rack (1.6.0.beta) lib/rack/lint.rb:49:in `_call'
rack (1.6.0.beta) lib/rack/lint.rb:37:in `call'
rack (1.6.0.beta) lib/rack/showexceptions.rb:24:in `call'
rack (1.6.0.beta) lib/rack/commonlogger.rb:33:in `call'
rack (1.6.0.beta) lib/rack/chunked.rb:54:in `call'
rack (1.6.0.beta) lib/rack/content_length.rb:15:in `call'
rack (1.6.0.beta) lib/rack/handler/webrick.rb:89:in `service'
() home/pubudu/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
() home/pubudu/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
() home/pubudu/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
127.0.0.1 - - [27/Nov/2014:18:19:09 +0530] "GET /uploaded HTTP/1.1" 500 - 0.0743
Update :
I set the correct file path like this :
send_file "#{file.filename.file}"
But then it gives this error :
Cannot read file #<CarrierWave::SanitizedFile:0x007f570c2b9e58>
Is my routes correct?
As per your setup CarrierWave should save your file inside "/home/pubudu/Projects/istockseller/public/uploads/tobereviewed/thpubs/#{model.user.username.downcase}/somefile.ext"
So, ideally your code should be
send_file "#{Rails.root}/public/#{file.image.url}"
Assuming your upload column is image.
Setup debugger in the controller's action.
def uploaded
file = Submit.first
debugger
send_file "#{file.filename.file}"
end
Now, request the action again and go to the debugger console. A tip here is to open "irb" inside the debugger. Just type "irb" and hit enter.
See what file.filename.file is returning. I believe it's an invalid path, so check if the file exists in your filesystem. Then, you can reproduce the next step (send_file) and check the error log.
I'd then advise you to open the source code of CarrierWave gem in your computer and find what's wrong with your code.
In your terminal, go to your project directory and run:
bundle show carrierwave
This will print you the path of the carrierwave gem's source you are using. Open it in your editor and find what's wrong with your code, according to the error log!
Tip
If you provide the current error log (after your update), we may help you better.
Cannot read file #<CarrierWave::SanitizedFile:0x007f570c2b9e58>
is not enough. The full backtrace would be better than this "one line" of code (use pastebin whenever possible).
Related
My Rails application throws an ActionController::InvalidAuthenticityToken from time to time. It occurs spontaneously once a month or so. As I don't think that there is some other site trying a CSRF attack, I started to make my thoughts about this rare events. My conclusion so far:
Random robots?
People waiting too long to send the form so that it expires on the server?
Are there other reasons for such false positive rejections?
And please don't explain what CSRF is ;-)
Here are some logs...
F, [2016-12-06T16:03:59.050673 #15136] FATAL -- :
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
actionpack (4.2.7) lib/action_controller/metal/request_forgery_protection.rb:181:in `handle_unverified_request'
actionpack (4.2.7) lib/action_controller/metal/request_forgery_protection.rb:209:in `handle_unverified_request'
devise (4.2.0) lib/devise/controllers/helpers.rb:253:in `handle_unverified_request'
actionpack (4.2.7) lib/action_controller/metal/request_forgery_protection.rb:204:in `verify_authenticity_token'
activesupport (4.2.7) lib/active_support/callbacks.rb:432:in `block in make_lambda'
activesupport (4.2.7) lib/active_support/callbacks.rb:164:in `block in halting'
activesupport (4.2.7) lib/active_support/callbacks.rb:504:in `block in call'
activesupport (4.2.7) lib/active_support/callbacks.rb:504:in `each'
activesupport (4.2.7) lib/active_support/callbacks.rb:504:in `call'
activesupport (4.2.7) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
activesupport (4.2.7) lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
activesupport (4.2.7) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.7) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.7) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.7) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.7) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.7) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.7) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.7) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.7) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
actionpack (4.2.7) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.7) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.7) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.7) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.7) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.7) lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
actionpack (4.2.7) lib/action_dispatch/routing/route_set.rb:43:in `serve'
actionpack (4.2.7) lib/action_dispatch/routing/mapper.rb:49:in `serve'
actionpack (4.2.7) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.7) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.7) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.7) lib/action_dispatch/routing/route_set.rb:817:in `call'
turnout (2.3.1) lib/rack/turnout.rb:25:in `call'
omniauth (1.3.1) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.3.1) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.3.1) lib/omniauth/strategy.rb:186:in `call!'
omniauth (1.3.1) lib/omniauth/strategy.rb:164:in `call'
rack-attack (4.4.1) lib/rack/attack.rb:107:in `call'
exception_notification (4.2.1) lib/exception_notification/rack.rb:32:in `call'
warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
warden (1.2.6) lib/warden/manager.rb:34:in `catch'
warden (1.2.6) lib/warden/manager.rb:34:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:38:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.7) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.7) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.7) lib/action_dispatch/middleware/cookies.rb:560:in `call'
actionpack (4.2.7) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.7) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
activesupport (4.2.7) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
activesupport (4.2.7) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.7) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.7) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.7) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.2.7) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.7) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.7) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.7) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.7) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.7) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.7) lib/rails/rack/logger.rb:20:in `call'
ahoy_matey (1.4.2) lib/ahoy/engine.rb:22:in `call_with_quiet_ahoy'
request_store (1.3.1) lib/request_store/middleware.rb:9:in `call'
actionpack (4.2.7) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.7) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
actionpack (4.2.7) lib/action_dispatch/middleware/ssl.rb:24:in `call'
railties (4.2.7) lib/rails/engine.rb:518:in `call'
railties (4.2.7) lib/rails/application.rb:165:in `call'
/usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:160:in `accept_and_process_next_request'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:113:in `main_loop'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:416:in `block (3 levels) in start_threads'
/usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'
I am with Dorian on this one as for the solution.
If you're looking to the cause I'm fairly positive that this issue report in rails github hits true, especially this little section:
# Browser quits, clearing session cookies
# Browser re-opens, reloads the page from cache without doing a request
This is especially true since by defualt Rails uses turbolinks which encourages caching (by default 10 pages if I recall).
Another way this can be potentially replicated is by having a user load your DOM (and thus your cookies / session) and then having them manually destroy their session or cookies through the browser management tools (e.g: chrome://settings). This should also reproduce the error since you will have the hidden tag for csrf in the form, but not the session cookie... and you need both.
You should probably null the session in your production environment instead of throwing an exception:
In you ApplicationController (or any controller you are concerned about) add:
protect_from_forgery with: :null_session
If you are really worried about it, my advice would be to log to error to Bugsnag for instance and there you will be able to review the request and understand why it happened.
I have two devise models- Student and Teacher. All of my Rspec tests are passing, which must go through the sign up/sign in process. The thing is, the exact same code works on a friend's computer, however, when I run the rails server on my machine, and try to access the teacher sign in form by going to http://localhost:3000/teachers/sign_in, I get this stack trace in my terminal:
ArgumentError in Devise::SessionsController#new
wrong number of arguments (2 for 1)
Here is my full stack trace from the terminal:
Started GET "/teachers/sign_in" for ::1 at 2016-04-09 13:39:11 +0100
Processing by Devise::SessionsController#new as HTML
Completed 500 Internal Server Error in 1ms (ActiveRecord: 0.0ms)
ArgumentError (wrong number of arguments (2 for 1)):
devise (3.5.6) lib/devise.rb:464:in `[]'
devise (3.5.6) lib/devise.rb:464:in `block (2 levels) in configure_warden!'
warden (1.2.6) lib/warden/session_serializer.rb:34:in `fetch'
warden (1.2.6) lib/warden/proxy.rb:212:in `user'
warden (1.2.6) lib/warden/proxy.rb:322:in `_perform_authentication'
warden (1.2.6) lib/warden/proxy.rb:104:in `authenticate'
warden (1.2.6) lib/warden/proxy.rb:114:in `authenticate?'
devise (3.5.6) app/controllers/devise_controller.rb:103:in `require_no_authentication'
activesupport (4.2.5) lib/active_support/callbacks.rb:432:in `block in make_lambda'
activesupport (4.2.5) lib/active_support/callbacks.rb:145:in `call'
activesupport (4.2.5) lib/active_support/callbacks.rb:145:in `block in halting_and_conditional'
activesupport (4.2.5) lib/active_support/callbacks.rb:504:in `call'
activesupport (4.2.5) lib/active_support/callbacks.rb:504:in `block in call'
activesupport (4.2.5) lib/active_support/callbacks.rb:504:in `each'
activesupport (4.2.5) lib/active_support/callbacks.rb:504:in `call'
activesupport (4.2.5) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
activesupport (4.2.5) lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
activesupport (4.2.5) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.5) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.5) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.5) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.5) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.5) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.5) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.5) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.5) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.5) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.5) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.5) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.5) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:76:in `call'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:45:in `serve'
actionpack (4.2.5) lib/action_dispatch/routing/mapper.rb:49:in `serve'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:817:in `call'
warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
warden (1.2.6) lib/warden/manager.rb:34:in `catch'
warden (1.2.6) lib/warden/manager.rb:34:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.5) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
activerecord (4.2.5) lib/active_record/migration.rb:377:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.5) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
activesupport (4.2.5) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
activesupport (4.2.5) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.5) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.5) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.5) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.5) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.5) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.5) lib/action_dispatch/middleware/static.rb:116:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.5) lib/rails/engine.rb:518:in `call'
railties (4.2.5) lib/rails/application.rb:165:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
/Users/charlieperson/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/Users/charlieperson/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/Users/charlieperson/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
Rendered /Users/charlieperson/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_source.erb (3.8ms)
Rendered /Users/charlieperson/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.7ms)
Rendered /Users/charlieperson/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.8ms)
Rendered /Users/charlieperson/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (45.7ms)
Rendered /Users/charlieperson/.rvm/gems/ruby-2.2.3/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (0.6ms)
Rendered /Users/charlieperson/.rvm/gems/ruby-2.2.3/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.2ms)
Rendered /Users/charlieperson/.rvm/gems/ruby-2.2.3/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.3ms)
Rendered /Users/charlieperson/.rvm/gems/ruby-2.2.3/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.3ms)
Rendered /Users/charlieperson/.rvm/gems/ruby-2.2.3/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb within layouts/javascript (40.8ms)
Rendered /Users/charlieperson/.rvm/gems/ruby-2.2.3/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb within layouts/javascript (0.2ms)
Rendered /Users/charlieperson/.rvm/gems/ruby-2.2.3/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.3ms)
Rendered /Users/charlieperson/.rvm/gems/ruby-2.2.3/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (90.3ms)
The devise sign up/sign in form does show up correctly when I go to http://localhost:3000/students/sign_in but once I click log in I get this error:
ArgumentError in DashboardController#index
wrong number of arguments (2 for 1)
def index
#student = current_student
#teacher = current_teacher (It doesn't like this line)
end
Essentially, it refuses to recognize or let me use the devise helper methods. Any help would be greatly appreciated. If this is not clear enough, please let me know. I searched for an answer for a very long time, tried many proposed solutions, without any luck.
It's caused by this line inside the devise gem, which suggests that key is not what devise expects it to be, perhaps there's something in your session that devise is choking on.
Try resetting your session (have your friend do the same on his computer) by deleting your browser cookies for your site.
I can't find a solution. I would like to create new User in my web application (with Devise). Please, read the notes below:
My current OS: Ubuntu 15
Previous OS: Linux Mint
(On Mac OS X it works correctly)
Terminal log:
Started POST "/users" for 127.0.0.1 at 2016-03-04 00:40:32 +0300
Processing by Users::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"OmTevxMT8IYxO8fcWHJU75gsLhVlj6/dLctvU2PhIWnlsEZ2B0p0iCQClVmPbRKBBauBKfjwv1hRnP8kTC0sxg==", "user"=>{"name"=>"test", "surname"=>"test", "email"=>"test#test.ru", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Зарегистрироваться"}
(0.3ms) BEGIN
User Exists (0.7ms) SELECT 1 AS one FROM `users` WHERE `users`.`email` = BINARY 'test#test.ru' LIMIT 1
SQL (0.6ms) INSERT INTO `users` (`email`, `encrypted_password`, `name`, `surname`, `created_at`, `updated_at`) VALUES ('test#test.ru', '$2a$10$sY490xgy8sHCFJxfY2B80OSFV7s.p0qg8R03ZPLGjzGYqou8Lz6xC', 'test', 'test', '2016-03-03 21:40:32.488474', '2016-03-03 21:40:32.488474')
(44.3ms) COMMIT
Completed 500 Internal Server Error in 201ms
ArgumentError - argument out of range:
activesupport (4.2.0) lib/active_support/values/time_zone.rb:350:in `parse'
activesupport (4.2.0) lib/active_support/core_ext/string/zones.rb:9:in `in_time_zone'
activerecord (4.2.0) lib/active_record/attribute_methods/time_zone_conversion.rb:15:in `type_cast_from_user'
activerecord (4.2.0) lib/active_record/attribute.rb:100:in `type_cast'
activerecord (4.2.0) lib/active_record/attribute.rb:42:in `original_value'
activerecord (4.2.0) lib/active_record/attribute.rb:37:in `value'
activerecord (4.2.0) lib/active_record/attribute.rb:46:in `value_for_database'
activerecord (4.2.0) lib/active_record/attribute_methods/dirty.rb:164:in `store_original_raw_attribute'
activerecord (4.2.0) lib/active_record/attribute_methods/dirty.rb:93:in `write_attribute'
activerecord (4.2.0) lib/active_record/attribute_methods.rb:50:in `__temp__c6163747f5379676e6f596e6f59607'
devise (3.5.5) lib/devise/models/trackable.rb:24:in `update_tracked_fields'
devise (3.5.5) lib/devise/models/trackable.rb:32:in `update_tracked_fields!'
devise (3.5.5) lib/devise/hooks/trackable.rb:7:in `block in '
warden (1.2.6) lib/warden/hooks.rb:14:in `block in _run_callbacks'
warden (1.2.6) lib/warden/hooks.rb:9:in `_run_callbacks'
warden (1.2.6) lib/warden/manager.rb:51:in `_run_callbacks'
warden (1.2.6) lib/warden/proxy.rb:179:in `set_user'
devise (3.5.5) lib/devise/controllers/sign_in_out.rb:43:in `sign_in'
devise (3.5.5) app/controllers/devise/registrations_controller.rb:106:in `sign_up'
devise (3.5.5) app/controllers/devise/registrations_controller.rb:22:in `create'
app/controllers/users/registrations_controller.rb:12:in `create'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/mapper.rb:49:in `serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
warden (1.2.6) lib/warden/manager.rb:34:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:38:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
puma (2.16.0) lib/puma/server.rb:557:in `handle_request'
puma (2.16.0) lib/puma/server.rb:404:in `process_client'
puma (2.16.0) lib/puma/server.rb:270:in `block in run'
puma (2.16.0) lib/puma/thread_pool.rb:106:in `block in spawn_thread'
I have added changes to my model, but my error is the same:
class Something < ActiveRecord::Base
validate :important_date_is_valid_datetime, on: :create
validates :important_date, presence: true
private
def important_date_is_valid_datetime
if (DateTime.parse(important_date.to_s()) rescue ArgumentError) == ArgumentError then
errors.add(:important_date, 'must be a valid datetime')
end
end
end
Also, I have added the next code in my form:
class Something < ActiveRecord::Base
validate :important_date_is_valid_datetime, on: :create
validates :important_date, presence: true
private
def important_date_is_valid_datetime
if (DateTime.parse(important_date.to_s()) rescue ArgumentError) == ArgumentError then
errors.add(:important_date, 'must be a valid datetime')
end
end
end
Problem: I am trying to create a custom action that allows a teacher to approve a student via the "approve" action. The approve action fetches the appropriate row and changes the status from "pending" to "active" and saves the record. Currently when I click the link, better errors gives me a
"undefined method `permit' for "2":String"
it mentions something about
Devise::ParameterSanitizer#permit
Please keep in mind, I am very new to Devise and am stumped!
Controller
class Teachers::RegistrationsController < Devise::RegistrationsController
# APPROVE
def approve
#ts = TeacherStudent.find_by(teacher_id: params[:teacher], student_id: params[:student])
#ts.status = "active"
#ts.save
redirect_to teachers_path
end
end
View
= link_to "Approve", approve_path(teacher: s.teacher_id, student: s.student_id), method: :put
Routes.rb
put 'teachers' => 'teachers#approve', as: :approve
Error
Started PUT "/teachers?student=14&teacher=2" for ::1 at 2015-06-21 01:06:33 -0500
Processing by Teachers::RegistrationsController#update as HTML
Parameters: {"authenticity_token"=>"VQ2zVIv5gof1+38xdAA9d/Y+bWmHk4bT1SXHvc+xLr3+qTOm2xSMZUFjDw74umk35P36kgpqx4eMftFGyVThSg==", "student"=>"14", "teacher"=>"2"}
[1m[36mTeacher Load (0.6ms)[0m [1mSELECT "teachers".* FROM "teachers" WHERE "teachers"."id" = $1 ORDER BY "teachers"."id" ASC LIMIT 1[0m [["id", 2]]
[1m[35mTeacher Load (0.3ms)[0m SELECT "teachers".* FROM "teachers" WHERE "teachers"."id" = $1 LIMIT 1 [["id", 2]]
Completed 500 Internal Server Error in 5ms (ActiveRecord: 1.0ms)
NoMethodError - undefined method `permit' for "2":String:
() Users/dannysun/.rvm/gems/ruby-2.2.1/bundler/gems/devise-15b99977a2a3/lib/devise/parameter_sanitizer.rb:66:in `permit'
() Users/dannysun/.rvm/gems/ruby-2.2.1/bundler/gems/devise-15b99977a2a3/lib/devise/parameter_sanitizer.rb:58:in `account_update'
() Users/dannysun/.rvm/gems/ruby-2.2.1/bundler/gems/devise-15b99977a2a3/lib/devise/parameter_sanitizer.rb:77:in `default_sanitize'
() Users/dannysun/.rvm/gems/ruby-2.2.1/bundler/gems/devise-15b99977a2a3/lib/devise/parameter_sanitizer.rb:24:in `sanitize'
() Users/dannysun/.rvm/gems/ruby-2.2.1/bundler/gems/devise-15b99977a2a3/app/controllers/devise/registrations_controller.rb:141:in `account_update_params'
() Users/dannysun/.rvm/gems/ruby-2.2.1/bundler/gems/devise-15b99977a2a3/app/controllers/devise/registrations_controller.rb:48:in `update'
actionpack (4.2.1) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.1) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.1) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
activesupport (4.2.1) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:776:in `_run_process_action_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.1) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.1) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.1) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.1) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.1) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.1) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.1) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:43:in `serve'
actionpack (4.2.1) lib/action_dispatch/routing/mapper.rb:49:in `serve'
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:819:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:38:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.1) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:649:in `call'
activerecord (4.2.1) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.1) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:776:in `_run_call_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.1.3) lib/web_console/middleware.rb:37:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.1) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.1) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.1) lib/rails/engine.rb:518:in `call'
railties (4.2.1) lib/rails/application.rb:164:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
/Users/dannysun/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/Users/dannysun/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/Users/dannysun/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
The problem is most likely in your permissions.
Are you using Strong Parameters? If so, you need to permit the fields in there.
Example:
def teacher_params
params.require(:teacher).permit(:email, :current_password, :password, :password_confirmation)
end
Add the following code at the bottom of your Teachers Controller-
private
def user_params
accessible = [:email, _____] # extend with your own params
accessible << [ :password, :password_confirmation ] unless params[:teacher][:password].blank?
params.require(:teacher).permit(accessible)
end
I use gem activeadmin. Every time, when I login, I get the error.
ActionController::ActionControllerError in ActiveAdmin::Devise::SessionsController#new
raise ActionControllerError.new("Cannot redirect to nil!") unless options
on url: http://localhost:3000/admin/login
But if I go to this url http://localhost:3000/admin
activeadmin is working, but writing You are already signed in.
routes.rb
ActiveAdmin.routes(self)
#settings activeadmin
devise_for :admin_users, ActiveAdmin::Devise.config
#settings devise
devise_for :users, controllers: { sessions: "sessions", registrations: "registrations" }
get 'persons/profile'
application_controller.rb
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
def after_sign_in_path_for(resource)
request.referer
end
def after_sign_out_path_for(resource_or_scope)
root_path
end
log
Started GET "/admin/login" for 127.0.0.1 at 2015-05-06 10:49:04 +0600
Processing by ActiveAdmin::Devise::SessionsController#new as HTML
AdminUser Load (0.3ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT 1 [["id", 2]]
Redirected to
Completed 500 Internal Server Error in 4ms (ActiveRecord: 0.3ms)
ActionController::ActionControllerError (Cannot redirect to nil!):
actionpack (4.2.1) lib/action_controller/metal/redirecting.rb:70:in `redirect_to'
actionpack (4.2.1) lib/action_controller/metal/flash.rb:57:in `redirect_to'
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:64:in `block in redirect_to'
activesupport (4.2.1) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.1) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:63:in `redirect_to'
devise (3.4.1) app/controllers/devise_controller.rb:110:in `require_no_authentication'
activesupport (4.2.1) lib/active_support/callbacks.rb:432:in `block in make_lambda'
activesupport (4.2.1) lib/active_support/callbacks.rb:145:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:145:in `block in halting_and_conditional'
activesupport (4.2.1) lib/active_support/callbacks.rb:504:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:504:in `block in call'
activesupport (4.2.1) lib/active_support/callbacks.rb:504:in `each'
activesupport (4.2.1) lib/active_support/callbacks.rb:504:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:776:in `_run_process_action_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.1) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.1) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
searchkick (0.8.7) lib/searchkick/logging.rb:107:in `process_action'
activerecord (4.2.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.1) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.1) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.1) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.1) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.1) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:74:in `call'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:43:in `serve'
actionpack (4.2.1) lib/action_dispatch/routing/mapper.rb:49:in `serve'
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:819:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.0) lib/rack/etag.rb:24:in `call'
rack (1.6.0) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.0) lib/rack/head.rb:13:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.0) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.0) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.1) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:649:in `call'
activerecord (4.2.1) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.1) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:776:in `_run_call_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.1.2) lib/web_console/middleware.rb:37:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.1) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.1) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.0) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
railties (4.2.1) lib/rails/engine.rb:518:in `call'
railties (4.2.1) lib/rails/application.rb:164:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
rack (1.6.0) lib/rack/content_length.rb:15:in `call'
rack (1.6.0) lib/rack/handler/webrick.rb:89:in `service'
/home/maratovich/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
/home/maratovich/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
/home/maratovich/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
Found many issues but not helped me
YES Solved...
First:
Method after_sign_in_path_for should be in module protected
Second in this method I added root_path || user_admin_path
Result is:
protected
def after_sign_in_path_for(resource_or_scope)
root_path || user_admin_path
end