Hi,
I need your help with cancan.
I have this controler:
class RegistrationsController < Devise::RegistrationsController
I needed because I had to overwrite some methods.
I need to control the access to this controller because the administrator is the only that can add a new user.
How can I use load_and_authorize_resource?
My ability.rb file is:
class Ability
include CanCan::Ability
def initialize(user, controller_namespace)
user ||= Usuario.new
case controller_namespace
when "Administrator"
if user.rol == 1
can :manage, Faq
can :manage, Tip
can :manage, Administrator::HomeTratamientoController
end
if user.rol == 2
can :manage, :admin_vacunas
can :manage, Registration
end
when "paciente"
if user.rol == 3
can :manage, Paciente::HomeController
end
else
can :read, :all
end
end
The model is usuario.rb
I don't have problem when the rol is 1 but when is 2, and I put the line:
load_and_authorize_resource
when in the registration controller I call the action new to add a new user by the adminstrator, show me the follow error:
Completed 500 Internal Server Error in 42ms (ActiveRecord: 5.1ms)
NameError - uninitialized constant Registration:
activesupport (4.2.1) lib/active_support/dependencies.rb:533:in load_missing_constant'
activesupport (4.2.1) lib/active_support/dependencies.rb:184:inconst_missing'
activesupport (4.2.1) lib/active_support/inflector/methods.rb:261:in block in constantize'
activesupport (4.2.1) lib/active_support/inflector/methods.rb:259:inconstantize'
activesupport (4.2.1) lib/active_support/core_ext/string/inflections.rb:66:in constantize'
cancancan (2.0.0) lib/cancan/controller_resource.rb:156:inresource_class'
cancancan (2.0.0) lib/cancan/controller_resource.rb:192:in resource_base'
cancancan (2.0.0) lib/cancan/controller_resource.rb:80:inbuild_resource'
cancancan (2.0.0) lib/cancan/controller_resource.rb:61:in load_resource_instance'
cancancan (2.0.0) lib/cancan/controller_resource.rb:35:inload_resource'
cancancan (2.0.0) lib/cancan/controller_resource.rb:12:in block in add_before_action'
activesupport (4.2.1) lib/active_support/callbacks.rb:448:inblock in make_lambda'
activesupport (4.2.1) lib/active_support/callbacks.rb:164:in block in halting'
activesupport (4.2.1) lib/active_support/callbacks.rb:504:inblock in call'
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:inrun_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:inprocess_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:inblock 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:ininstrument'
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:inprocess_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:inprocess'
actionview (4.2.1) lib/action_view/rendering.rb:30:in process'
actionpack (4.2.1) lib/action_controller/metal.rb:196:indispatch'
actionpack (4.2.1) lib/action_controller/metal/rack_delegation.rb:13:in dispatch'
actionpack (4.2.1) lib/action_controller/metal.rb:237:inblock 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:inserve'
actionpack (4.2.1) lib/action_dispatch/routing/mapper.rb:49:in serve'
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:43:inblock 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:incall'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/rack/agent_hooks.rb:30:intraced_call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/rack/browser_monitoring.rb:32:intraced_call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/rack/developer_mode.rb:48:intraced_call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call'
warden (1.2.6) lib/warden/manager.rb:35:inblock in call'
warden (1.2.6) lib/warden/manager.rb:34:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
rack (1.6.4) lib/rack/etag.rb:24:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
rack (1.6.4) lib/rack/conditionalget.rb:25:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
rack (1.6.4) lib/rack/head.rb:13:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
actionpack (4.2.1) lib/action_dispatch/middleware/params_parser.rb:27:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
actionpack (4.2.1) lib/action_dispatch/middleware/flash.rb:260:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:incall'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call'
actionpack (4.2.1) lib/action_dispatch/middleware/cookies.rb:560:incall'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call'
activerecord (4.2.1) lib/active_record/query_cache.rb:36:incall'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call'
activerecord (4.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:649:incall'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call'
activerecord (4.2.1) lib/active_record/migration.rb:378:incall'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call'
actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:29:inblock 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:incall'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call'
actionpack (4.2.1) lib/action_dispatch/middleware/reloader.rb:73:incall'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call'
actionpack (4.2.1) lib/action_dispatch/middleware/remote_ip.rb:78:incall'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call'
better_errors (2.1.1) lib/better_errors/middleware.rb:84:inprotected_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:incall'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call'
actionpack (4.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:incall'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call'
web-console (2.3.0) lib/web_console/middleware.rb:28:inblock in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
actionpack (4.2.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
railties (4.2.1) lib/rails/rack/logger.rb:38:in call_app'
railties (4.2.1) lib/rails/rack/logger.rb:20:inblock 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:intagged'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in tagged'
railties (4.2.1) lib/rails/rack/logger.rb:20:incall'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in call_with_quiet_assets'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
actionpack (4.2.1) lib/action_dispatch/middleware/request_id.rb:21:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
rack (1.6.4) lib/rack/methodoverride.rb:22:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
rack (1.6.4) lib/rack/runtime.rb:18:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
activesupport (4.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
rack (1.6.4) lib/rack/lock.rb:17:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
actionpack (4.2.1) lib/action_dispatch/middleware/static.rb:113:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
rack (1.6.4) lib/rack/sendfile.rb:113:in call'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:incall'
railties (4.2.1) lib/rails/engine.rb:518:in call'
railties (4.2.1) lib/rails/application.rb:164:incall'
newrelic_rpm (3.16.1.320) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in call'
rack (1.6.4) lib/rack/content_length.rb:15:incall'
thin (1.7.0) lib/thin/connection.rb:86:in block in pre_process'
thin (1.7.0) lib/thin/connection.rb:84:inpre_process'
thin (1.7.0) lib/thin/connection.rb:53:in process'
thin (1.7.0) lib/thin/connection.rb:39:inreceive_data'
eventmachine (1.2.0.1) lib/eventmachine.rb:194:in run'
thin (1.7.0) lib/thin/backends/base.rb:73:instart'
thin (1.7.0) lib/thin/server.rb:162:in start'
rack (1.6.4) lib/rack/handler/thin.rb:19:inrun'
rack (1.6.4) lib/rack/server.rb:286:in start'
railties (4.2.1) lib/rails/commands/server.rb:80:instart'
railties (4.2.1) lib/rails/commands/commands_tasks.rb:80:in block in server'
railties (4.2.1) lib/rails/commands/commands_tasks.rb:75:inserver'
railties (4.2.1) lib/rails/commands/commands_tasks.rb:39:in run_command!'
railties (4.2.1) lib/rails/commands.rb:17:in'
bin/rails:9:in <top (required)>'
spring (1.7.2) lib/spring/client/rails.rb:28:incall'
spring (1.7.2) lib/spring/client/command.rb:7:in call'
spring (1.7.2) lib/spring/client.rb:30:inrun'
spring (1.7.2) bin/spring:49:in <top (required)>'
spring (1.7.2) lib/spring/binstub.rb:11:in'
bin/spring:13:in <top (required)>'
bin/rails:3:in'
Some body can help me please?
You wrote can :manage, Registration, so you need a Registration model.
In your case you should replace it with:
can :create, User
and in the controller you load_and_authorize_resource :user, parent: false
https://github.com/CanCanCommunity/cancancan/wiki/authorizing-controller-actions
Free tip:
don't write model names in Spanish, but in English, always. So replace Usuario with User.
Related
I have a Rails app and have implemented geolocalization: with geocoder gem, I detect the ip and know which country the user is accessing pages from.
I'd like to add a 'country' attribute to the User table.
Users would come to the sign-up page and without them knowing I would detect for example they are accessing the app from Finland.
Then when they sign up in by filling in the 2 fields email & password, I would save email and password but I want to save/store the country I get using geocoder in this column 'country'.
How can I save this 'country' attribute if I don't have the field in the form ?
Sounds easy but I only know how to save values when there actually is a form field the user fills in.
Here what I did:
/app/controllers/confirmations_controller.rb
def after_sign_up_path_for(resource)
if Devise.allow_insecure_sign_in_after_confirmation
resource.update(user_country: request.location.country)
after_sign_in_path_for(resource)
else
resource.update(user_country: request.location.country)
root_path
end
end
What's weird is that the user is saved with everything fine (including location) on my local database. But then something must happen as I get an error page with the following error message:
undefined method `model_name' for TrueClass:Class
The whole error log
(0.8ms) COMMIT
(0.5ms) BEGIN
SQL (1.3ms) UPDATE "users" SET "remember_created_at" = $1, "updated_at" = $2 WHERE "users"."id" = 427 [["remember_created_at", 2014-06-24 10:52:32 UTC], ["updated_at", 2014-06-24 12:52:32 +0200]]
(0.7ms) COMMIT
(0.4ms) BEGIN
SQL (0.9ms) UPDATE "users" SET "last_sign_in_at" = $1, "current_sign_in_at" = $2, "last_sign_in_ip" = $3, "current_sign_in_ip" = $4, "sign_in_count" = $5, "updated_at" = $6 WHERE "users"."id" = 427 [["last_sign_in_at", 2014-06-24 10:52:32 UTC], ["current_sign_in_at", 2014-06-24 10:52:32 UTC], ["last_sign_in_ip", "24.193.83.1"], ["current_sign_in_ip", "24.193.83.1"], ["sign_in_count", 1], ["updated_at", 2014-06-24 12:52:32 +0200]]
(0.7ms) COMMIT
(0.4ms) BEGIN
User Exists (1.0ms) SELECT 1 AS one FROM "users" WHERE (LOWER("users"."email") = LOWER('mathieu.proffit75++edaaaaaa+++#gmail.com') AND "users"."id" != 427) LIMIT 1
SQL (1.3ms) UPDATE "users" SET "user_country" = $1, "updated_at" = $2 WHERE "users"."id" = 427 [["user_country", "United States"], ["updated_at", 2014-06-24 12:52:32 +0200]]
(0.7ms) COMMIT
Completed 500 Internal Server Error in 4984ms
NoMethodError - undefined method `model_name' for TrueClass:Class:
actionpack (4.0.5) lib/action_controller/model_naming.rb:9:in `model_name_from_record_or_class'
actionpack (4.0.5) lib/action_dispatch/routing/polymorphic_routes.rb:182:in `build_named_route_call'
actionpack (4.0.5) lib/action_dispatch/routing/polymorphic_routes.rb:120:in `polymorphic_url'
actionpack (4.0.5) lib/action_dispatch/routing/url_for.rb:159:in `url_for'
actionpack (4.0.5) lib/action_controller/metal/rendering.rb:68:in `_process_options'
actionpack (4.0.5) lib/action_controller/metal/streaming.rb:202:in `_process_options'
actionpack (4.0.5) lib/abstract_controller/rendering.rb:119:in `render_to_body'
actionpack (4.0.5) lib/action_controller/metal/rendering.rb:33:in `render_to_body'
actionpack (4.0.5) lib/action_controller/metal/renderers.rb:26:in `render_to_body'
actionpack (4.0.5) lib/abstract_controller/rendering.rb:97:in `render'
actionpack (4.0.5) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.0.5) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
activesupport (4.0.5) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/home/mreisner/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
activesupport (4.0.5) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.0.5) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
actionpack (4.0.5) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (4.0.5) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.0.5) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (4.0.5) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.0.5) lib/action_controller/metal/responder.rb:233:in `default_render'
actionpack (4.0.5) lib/action_controller/metal/responder.rb:161:in `to_html'
actionpack (4.0.5) lib/action_controller/metal/responder.rb:154:in `respond'
actionpack (4.0.5) lib/action_controller/metal/responder.rb:147:in `call'
actionpack (4.0.5) lib/action_controller/metal/mime_responds.rb:330:in `respond_with'
devise (3.2.4) app/controllers/devise/registrations_controller.rb:20:in `create'
actionpack (4.0.5) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.5) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.5) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.5) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.5) lib/active_support/callbacks.rb:483:in `_run__1192109421260337467__process_action__callbacks'
activesupport (4.0.5) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.5) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.5) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.5) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.5) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.5) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.5) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.5) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.5) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.0.5) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.5) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.5) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.5) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.5) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.5) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.5) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.5) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.5) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.5) lib/action_dispatch/routing/mapper.rb:44:in `call'
actionpack (4.0.5) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.5) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.5) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.5) lib/action_dispatch/routing/route_set.rb:674: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.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:35:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.5) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.5) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.5) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.5) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.5) lib/active_record/migration.rb:373:in `call'
actionpack (4.0.5) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.5) lib/active_support/callbacks.rb:373:in `_run__3240580690818246217__call__callbacks'
activesupport (4.0.5) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.5) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.5) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.5) lib/action_dispatch/middleware/remote_ip.rb:76: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'
actionpack (4.0.5) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.5) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.5) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.5) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.0.5) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.0.5) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.0.5) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.0.2) lib/quiet_assets.rb:18:in `call_with_quiet_assets'
actionpack (4.0.5) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.5) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.5) lib/rails/engine.rb:511:in `call'
railties (4.0.5) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/home/mreisner/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/mreisner/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/mreisner/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
I'd probably try to catch the user after they sign up. You can read more on how to do it in the docs Devise: How to Redirect after Registration
Override the Devise Registration Controller with something like this:
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
resource.update(location: request.location)
root_path
end
end
That is untested code but should get you in the right direction. The second line of the method returns a redirect to the root_path after signup which you might want to change.
I am trying to do is when I click on view on the free page which is associated to list of companies and which should be asking me login but still I could able to do. Now it caused me an another problem after logged in when I click on the view of my list of companies it is showing me the following error.
I don't know which is causing the error. Can any one tell me what was the error and how to solve it.
And I don't have any method called login_required which I have before but I commented it.
Error is
Started GET "/company_ratings/user_rating?company_id=3" for 127.0.0.1 at 2014-01-22 10:11:34 +0100
Processing by CompanyRatingsController#user_rating as */*
Parameters: {"company_id"=>"3"}
Completed 500 Internal Server Error in 5ms
NameError (undefined local variable or method `login_required' for #<CompanyRatingsController:0x007f0c58948638>):
activesupport (4.0.2) lib/active_support/callbacks.rb:417:in `_run__2756769731211350067__process_action__callbacks'
activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.2) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.2) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.2) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.2) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.2) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.2) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.2) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.2) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.2) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.2) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.2) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.2) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.2) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.2) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.2) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.2) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.2) lib/action_dispatch/routing/route_set.rb:680: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.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.2) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.2) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.2) lib/active_support/callbacks.rb:373:in `_run__4080584768372332668__call__callbacks'
activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.2) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.2) lib/rails/engine.rb:511:in `call'
railties (4.0.2) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/home/seshendra/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/seshendra/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/seshendra/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
Rendered /home/seshendra/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.7ms)
Rendered /home/seshendra/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.3ms)
Rendered /home/seshendra/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.2ms)
Rendered /home/seshendra/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (18.0ms)
It looks that you are calling, the now extinct, login_required method from a before_action callback in one of your controllers.
Either you should remove the callback, or reinstate your method.
I've been working for the last two days (not long enough, it seems) to getting haml-rails to work with this RoR application. The backtrace I'm getting is this:
ActionView::MissingTemplate (Missing template customcare360/login, application/login with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder]}. Searched in:
* "/var/www/clients/client1/web54/capistrano/releases/20130403223833/app/views"
):
actionpack (3.2.11) lib/action_view/path_set.rb:58:in `find'
actionpack (3.2.11) lib/action_view/lookup_context.rb:109:in `find'
actionpack (3.2.11) lib/action_view/renderer/abstract_renderer.rb:3:in `find_template'
actionpack (3.2.11) lib/action_view/renderer/template_renderer.rb:34:in `determine_template'
actionpack (3.2.11) lib/action_view/renderer/template_renderer.rb:10:in `render'
actionpack (3.2.11) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.11) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.11) lib/abstract_controller/rendering.rb:110:in `_render_template'
actionpack (3.2.11) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.11) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.11) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.11) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.11) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.11) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.11) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/usr/local/rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
activesupport (3.2.11) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.11) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.2.11) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.2.11) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (3.2.11) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.11) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.11) lib/active_support/callbacks.rb:414:in `_run__3579697130236064177__process_action__869676858511540114__callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.11) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.11) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.11) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.11) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.11) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.11) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.11) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.11) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.11) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.11) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:601:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.11) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.11) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `_run__3196186370685956669__call__1689534214956595528__callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.11) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.11) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.11) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.11) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.11) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/static.rb:62:in `call'
rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
rack-cache (1.2) lib/rack/cache/context.rb:245:in `fetch'
rack-cache (1.2) lib/rack/cache/context.rb:185:in `lookup'
rack-cache (1.2) lib/rack/cache/context.rb:66:in `call!'
rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
railties (3.2.11) lib/rails/engine.rb:479:in `call'
railties (3.2.11) lib/rails/application.rb:223:in `call'
railties (3.2.11) lib/rails/railtie/configurable.rb:30:in `method_missing'
unicorn (4.6.2) lib/unicorn/http_server.rb:552:in `process_client'
unicorn (4.6.2) lib/unicorn/http_server.rb:632:in `worker_loop'
unicorn (4.6.2) lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
unicorn (4.6.2) lib/unicorn/http_server.rb:142:in `start'
unicorn (4.6.2) bin/unicorn:126:in `<top (required)>'
/var/www/ageless360-patient.theblsgroup.net/capistrano/shared/bundle/ruby/2.0.0/bin/unicorn:23:in `load'
/var/www/ageless360-patient.theblsgroup.net/capistrano/shared/bundle/ruby/2.0.0/bin/unicorn:23:in `<main>'
I've tried manually loading 'haml-rails' into my config/application.rb. My Gemfile looks like this:
source 'https://rubygems.org'
gem 'rails', '3.2.11'
# Environment-independent gems
gem 'mysql2'
gem 'json'
# Use unicorn as the app server
gem 'unicorn'
# HAML up the HTML.
gem 'haml'
gem 'haml-rails'
group :development do
# Provides an intuitve means of debugging in the browser.
gem 'better_errors'
# Remove unnecessary assets from being logged at dev time.
gem 'quiet_assets'
# Deploy with Capistrano
gem 'capistrano'
gem 'capistrano-ext'
gem 'capistrano-unicorn'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'jquery-rails'
end
I followed all instructions as given by https://github.com/louismullie/stanford-core-nlp and then installed JRE 1.6 as suggested in the attached article.
But now am getting an error which says
java.lang.NullPointerException
Am new to Ruby and have tried in all places to get anwer on what is happening.
actionpack (3.2.1) lib/action_controller/metal/rescue.rb:32:in rescue in process_action'
actionpack (3.2.1) lib/action_controller/metal/rescue.rb:29:inprocess_action'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:30:in block in process_action'
activesupport (3.2.1) lib/active_support/notifications.rb:123:inblock in instrument'
activesupport (3.2.1) lib/active_support/notifications/instrumenter.rb:20:in instrument'
activesupport (3.2.1) lib/active_support/notifications.rb:123:ininstrument'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:29:in process_action'
actionpack (3.2.1) lib/action_controller/metal/params_wrapper.rb:205:inprocess_action'
activerecord (3.2.1) lib/active_record/railties/controller_runtime.rb:18:in process_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:121:inprocess'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:45:in process'
actionpack (3.2.1) lib/action_controller/metal.rb:203:indispatch'
actionpack (3.2.1) lib/action_controller/metal/rack_delegation.rb:14:in dispatch'
actionpack (3.2.1) lib/action_controller/metal.rb:246:inblock in action'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:indispatch'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:30:in call'
journey (1.0.4) lib/journey/router.rb:68:inblock in call'
journey (1.0.4) lib/journey/router.rb:56:in each'
journey (1.0.4) lib/journey/router.rb:56:incall'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:589:in call'
omniauth (1.1.1) lib/omniauth/strategy.rb:177:incall!'
omniauth (1.1.1) lib/omniauth/strategy.rb:157:in call'
omniauth (1.1.1) lib/omniauth/builder.rb:48:incall'
actionpack (3.2.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in call'
rack (1.4.1) lib/rack/etag.rb:23:incall'
rack (1.4.1) lib/rack/conditionalget.rb:25:in call'
actionpack (3.2.1) lib/action_dispatch/middleware/head.rb:14:incall'
actionpack (3.2.1) lib/action_dispatch/middleware/params_parser.rb:21:in call'
actionpack (3.2.1) lib/action_dispatch/middleware/flash.rb:242:incall'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:incall'
actionpack (3.2.1) lib/action_dispatch/middleware/cookies.rb:338:in call'
activerecord (3.2.1) lib/active_record/query_cache.rb:64:incall'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in call'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:inblock in call'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in _run__3528916854062403214__call__361791269275604860__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in _run_call_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:inrun_callbacks'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in call'
actionpack (3.2.1) lib/action_dispatch/middleware/reloader.rb:65:incall'
actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in call'
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:incall'
actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in call'
railties (3.2.1) lib/rails/rack/logger.rb:26:incall_app'
railties (3.2.1) lib/rails/rack/logger.rb:16:in call'
actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:incall'
rack (1.4.1) lib/rack/methodoverride.rb:21:in call'
rack (1.4.1) lib/rack/runtime.rb:17:incall'
activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in call'
rack (1.4.1) lib/rack/lock.rb:15:incall'
actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in call'
railties (3.2.1) lib/rails/engine.rb:479:incall'
railties (3.2.1) lib/rails/application.rb:220:in call'
rack (1.4.1) lib/rack/content_length.rb:14:incall'
railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:inservice'
/usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:111:in service'
/usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:70:inrun'
/usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Had a working app with Rails 3.0.0beta4 and just updated to the RC. Getting a new strange error. For some reason when I try to:
<%= link_to "test", user %>
The user is routed as resources :users yet it complains about no route for "action => destroy" despite I'm not even trying to link to destroy:
ActionController::RoutingError in Main#index
No route matches {:action=>"destroy", :controller=>"users", :id=>#<User...>}
For reference I'm using
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
The route is simply:
resources :users
Running rake routes returns the proper stuff:
GET /users/:id(.:format) {:controller=>"users", :action=>"show"}
PUT /users/:id(.:format) {:controller=>"users", :action=>"update"}
user DELETE /users/:id(.:format) {:controller=>"users", :action=>"destroy"}
edit_user GET /users/:id/edit(.:format) {:controller=>"users", :action=>"edit"}
I generated a testrails app with scaffolding for users and it works just fine, so must be something in the full trace here. I'm stumped...
actionpack (3.0.0.rc) lib/action_dispatch/routing/route_set.rb:398:in `generate'
actionpack (3.0.0.rc) lib/action_dispatch/routing/route_set.rb:450:in `generate'
actionpack (3.0.0.rc) lib/action_dispatch/routing/route_set.rb:478:in `url_for'
actionpack (3.0.0.rc) lib/action_dispatch/routing/url_for.rb:132:in `url_for'
actionpack (3.0.0.rc) lib/action_view/helpers/url_helper.rb:99:in `url_for'
actionpack (3.0.0.rc) lib/action_dispatch/routing/route_set.rb:195:in `game_path'
actionpack (3.0.0.rc) lib/action_dispatch/routing/polymorphic_routes.rb:114:in `send'
actionpack (3.0.0.rc) lib/action_dispatch/routing/polymorphic_routes.rb:114:in `polymorphic_url'
actionpack (3.0.0.rc) lib/action_dispatch/routing/polymorphic_routes.rb:120:in `polymorphic_path'
actionpack (3.0.0.rc) lib/action_view/helpers/url_helper.rb:103:in `url_for'
actionpack (3.0.0.rc) lib/action_view/helpers/url_helper.rb:236:in `link_to'
app/views/main/index.html.erb:10:in `_app_views_main_index_html_erb__58309089_2173261620_0'
app/views/main/index.html.erb:8:in `each'
app/views/main/index.html.erb:8:in `_app_views_main_index_html_erb__58309089_2173261620_0'
actionpack (3.0.0.rc) lib/action_view/template.rb:135:in `send'
actionpack (3.0.0.rc) lib/action_view/template.rb:135:in `render'
activesupport (3.0.0.rc) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.0.rc) lib/action_view/template.rb:127:in `render'
actionpack (3.0.0.rc) lib/action_view/render/rendering.rb:59:in `_render_template'
activesupport (3.0.0.rc) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.0.rc) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.0.rc) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.0.rc) lib/action_view/render/rendering.rb:56:in `_render_template'
actionpack (3.0.0.rc) lib/action_view/render/rendering.rb:26:in `render'
actionpack (3.0.0.rc) lib/abstract_controller/rendering.rb:114:in `_render_template'
actionpack (3.0.0.rc) lib/abstract_controller/rendering.rb:108:in `render_to_body'
actionpack (3.0.0.rc) lib/action_controller/metal/renderers.rb:47:in `render_to_body'
actionpack (3.0.0.rc) lib/action_controller/metal/compatibility.rb:55:in `render_to_body'
actionpack (3.0.0.rc) lib/abstract_controller/rendering.rb:101:in `render_to_string'
actionpack (3.0.0.rc) lib/abstract_controller/rendering.rb:92:in `render'
actionpack (3.0.0.rc) lib/action_controller/metal/rendering.rb:17:in `render'
actionpack (3.0.0.rc) lib/action_controller/metal/instrumentation.rb:40:in `render'
activesupport (3.0.0.rc) lib/active_support/core_ext/benchmark.rb:5:in `ms'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:308:in `realtime'
activesupport (3.0.0.rc) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.0.0.rc) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (3.0.0.rc) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
activerecord (3.0.0.rc) lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
actionpack (3.0.0.rc) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.0.0.rc) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.0.0.rc) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (3.0.0.rc) lib/abstract_controller/base.rb:136:in `process_action'
actionpack (3.0.0.rc) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.0.rc) lib/abstract_controller/callbacks.rb:18:in `process_action'
activesupport (3.0.0.rc) lib/active_support/callbacks.rb:439:in `_run__1683250185__process_action__199225275__callbacks'
activesupport (3.0.0.rc) lib/active_support/callbacks.rb:404:in `send'
activesupport (3.0.0.rc) lib/active_support/callbacks.rb:404:in `_run_process_action_callbacks'
activesupport (3.0.0.rc) lib/active_support/callbacks.rb:93:in `send'
activesupport (3.0.0.rc) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.0.rc) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.0.rc) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
activesupport (3.0.0.rc) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.0.rc) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.0.rc) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.0.rc) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.0.rc) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.0.rc) lib/abstract_controller/base.rb:105:in `process'
actionpack (3.0.0.rc) lib/abstract_controller/rendering.rb:40:in `process'
actionpack (3.0.0.rc) lib/action_controller/metal.rb:133:in `dispatch'
actionpack (3.0.0.rc) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.0.rc) lib/action_controller/metal.rb:173:in `action'
actionpack (3.0.0.rc) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.0.rc) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.0.rc) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.9) lib/rack/mount/route_set.rb:148:in `call'
rack-mount (0.6.9) lib/rack/mount/code_generation.rb:89:in `recognize'
rack-mount (0.6.9) lib/rack/mount/code_generation.rb:66:in `optimized_each'
rack-mount (0.6.9) lib/rack/mount/code_generation.rb:88:in `recognize'
rack-mount (0.6.9) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.0.rc) lib/action_dispatch/routing/route_set.rb:489:in `call'
actionpack (3.0.0.rc) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.1) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.0.rc) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.0.rc) lib/action_dispatch/middleware/flash.rb:177:in `call'
actionpack (3.0.0.rc) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.0.rc) lib/action_dispatch/middleware/cookies.rb:268:in `call'
activerecord (3.0.0.rc) lib/active_record/query_cache.rb:32:in `call'
activerecord (3.0.0.rc) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.0.rc) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.0.rc) lib/active_record/query_cache.rb:31:in `call'
actionpack (3.0.0.rc) lib/action_dispatch/middleware/callbacks.rb:46:in `call'
activesupport (3.0.0.rc) lib/active_support/callbacks.rb:410:in `_run_call_callbacks'
actionpack (3.0.0.rc) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.1) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.0.rc) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.0.rc) lib/action_dispatch/middleware/show_exceptions.rb:48:in `call'
railties (3.0.0.rc) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.0.rc) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
rack (1.2.1) lib/rack/lock.rb:11:in `synchronize'
rack (1.2.1) lib/rack/lock.rb:11:in `call'
actionpack (3.0.0.rc) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.0.rc) lib/rails/application.rb:168:in `call'
railties (3.0.0.rc) lib/rails/application.rb:77:in `send'
railties (3.0.0.rc) lib/rails/application.rb:77:in `method_missing'
railties (3.0.0.rc) lib/rails/rack/log_tailer.rb:15:in `call'
rack (1.2.1) lib/rack/content_length.rb:13:in `call'
rack (1.2.1) lib/rack/handler/webrick.rb:52:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
rack (1.2.1) lib/rack/handler/webrick.rb:13:in `run'
rack (1.2.1) lib/rack/server.rb:213:in `start'
railties (3.0.0.rc) lib/rails/commands/server.rb:65:in `start'
railties (3.0.0.rc) lib/rails/commands.rb:30
railties (3.0.0.rc) lib/rails/commands.rb:27:in `tap'
railties (3.0.0.rc) lib/rails/commands.rb:27
script/rails:6:in `require'
script/rails:6
Could it be from these commits?
http://github.com/rails/rails/commit/a1e795f554e07476f1084a0c76cb8b033d1d0b0c
Help is much appreciated!
Ok heres the deal. I investigated the corresponding code and it was caused by two things. The problem was actually because I had my to_param set as follows:
def to_param
id + '/' + title.parameterize
end
I needed to keep compatability with old URLs from the non-rails app, thus the '/' rather than the usual -.
The fix is to replace '/' with '%2F'
Relevant commit: http://github.com/rails/rails/commit/622092d33e8d326217ab1ed6138e2c572c95b8ba
The problem you're having is that '/' is a separator in routes, so in order to match you'll need your route to look like
match 'users/:id/:slug', :to=>"users#show"
Either that, or escape the '/' to '%2F' as you said
I tried this and worked for me in Rails 3:
match "/:login" => "users#show_by_login", :as => 'show_user', :constraints => {:login => /.*/}