Rails 3.0.0 RC ActionController::RoutingError "No route matches" - ruby-on-rails-3

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 => /.*/}

Related

Jruby with Devise

I'm using devise-3.3.0 on jruby-1.7.13, I can't login or register when I hit /users/sign_up I get
ActionView::Template::Error (undefined method `new' for nil:NilClass):
Stacktrace
.rvm/gems/jruby-1.7.13/gems/devise-3.3.0/app/views/devise/registrations/new.html.erb within layouts/application (10.0ms)
Completed 500 Internal Server Error in 27ms
ActionView::Template::Error (undefined method `new' for nil:NilClass):
1: <h2>Sign up</h2>
2:
3: <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
4: <%= devise_error_messages! %>
5:
6: <div><%= f.label :email %><br />
actionview (4.1.4) lib/action_view/helpers/form_helper.rb:1146:in `instantiate_builder'
actionview (4.1.4) lib/action_view/helpers/form_helper.rb:433:in `form_for'
devise (3.3.0) app/views/devise/registrations/new.html.erb:3:in `___sers_magedmakled__rvm_gems_jruby________gems_devise_______app_views_devise_registrations_new_html_erb__1178479770_4328'
actionview (4.1.4) lib/action_view/template.rb:145:in `render'
activesupport (4.1.4) lib/active_support/notifications.rb:161:in `instrument'
actionview (4.1.4) lib/action_view/template.rb:339:in `instrument'
actionview (4.1.4) lib/action_view/template.rb:143:in `render'
actionview (4.1.4) lib/action_view/renderer/template_renderer.rb:55:in `render_template'
actionview (4.1.4) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
activesupport (4.1.4) lib/active_support/notifications.rb:159:in `instrument'
activesupport (4.1.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.1.4) lib/active_support/notifications.rb:159:in `instrument'
actionview (4.1.4) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionview (4.1.4) lib/action_view/renderer/template_renderer.rb:54:in `render_template'
actionview (4.1.4) lib/action_view/renderer/template_renderer.rb:62:in `render_with_layout'
actionview (4.1.4) lib/action_view/renderer/template_renderer.rb:53:in `render_template'
actionview (4.1.4) lib/action_view/renderer/template_renderer.rb:17:in `render'
actionview (4.1.4) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (4.1.4) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (4.1.4) lib/action_view/rendering.rb:99:in `_render_template'
actionpack (4.1.4) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (4.1.4) lib/action_view/rendering.rb:82:in `render_to_body'
actionpack (4.1.4) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
actionpack (4.1.4) lib/action_controller/metal/renderers.rb:32:in `render_to_body'
actionpack (4.1.4) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (4.1.4) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.1.4) lib/action_controller/metal/instrumentation.rb:41:in `render'
activesupport (4.1.4) lib/active_support/core_ext/benchmark.rb:12:in `ms'
/Users/magedmakled/.rvm/rubies/jruby-1.7.8/lib/ruby/1.9/benchmark.rb:295:in `realtime'
activesupport (4.1.4) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.1.4) lib/action_controller/metal/instrumentation.rb:41:in `render'
actionpack (4.1.4) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (4.1.4) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.1.4) lib/action_controller/metal/instrumentation.rb:40:in `render'
actionpack (4.1.4) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.1.4) lib/action_controller/metal/responder.rb:238:in `default_render'
actionpack (4.1.4) lib/action_controller/metal/responder.rb:165:in `to_html'
actionpack (4.1.4) lib/action_controller/metal/responder.rb:158:in `respond'
actionpack (4.1.4) lib/action_controller/metal/responder.rb:151:in `call'
actionpack (4.1.4) lib/action_controller/metal/mime_responds.rb:400:in `respond_with'
devise (3.3.0) app/controllers/devise/registrations_controller.rb:12:in `new'
actionpack (4.1.4) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.1.4) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.1.4) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.1.4) lib/abstract_controller/callbacks.rb:20:in `process_action'
org/jruby/RubyProc.java:271:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:113:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:229:in `halting'
org/jruby/RubyProc.java:271:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:229:in `halting'
org/jruby/RubyProc.java:271:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `halting'
org/jruby/RubyProc.java:271:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `halting'
org/jruby/RubyProc.java:271:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `halting'
org/jruby/RubyProc.java:271:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:166:in `halting'
org/jruby/RubyProc.java:271:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:149:in `halting_and_conditional'
org/jruby/RubyProc.java:271:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:149:in `halting_and_conditional'
org/jruby/RubyProc.java:271:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:86:in `run_callbacks'
actionpack (4.1.4) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.1.4) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.1.4) lib/action_controller/metal/instrumentation.rb:31:in `process_action'
activesupport (4.1.4) lib/active_support/notifications.rb:159:in `instrument'
activesupport (4.1.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.1.4) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.1.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.1.4) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.1.4) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.1.4) lib/abstract_controller/base.rb:136:in `process'
actionview (4.1.4) lib/action_view/rendering.rb:30:in `process'
actionpack (4.1.4) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.1.4) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.1.4) lib/action_controller/metal.rb:232:in `action'
org/jruby/RubyProc.java:271:in `call'
actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:50:in `call'
actionpack (4.1.4) lib/action_dispatch/routing/mapper.rb:45:in `call'
actionpack (4.1.4) lib/action_dispatch/journey/router.rb:71:in `call'
org/jruby/RubyArray.java:1613:in `each'
actionpack (4.1.4) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.1.4) lib/action_dispatch/routing/route_set.rb:678:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `call'
org/jruby/RubyKernel.java:1284: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.1.4) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/flash.rb:254: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.1.4) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.1.4) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.1.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
activerecord (4.1.4) lib/active_record/migration.rb:380:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/callbacks.rb:29:in `call'
activesupport (4.1.4) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.4) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.4) lib/rails/rack/logger.rb:20:in `call'
activesupport (4.1.4) lib/active_support/tagged_logging.rb:68:in `tagged'
activesupport (4.1.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.4) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.4) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
my routes
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
articles GET /articles(.:format) articles#index
POST /articles(.:format) articles#create
new_article GET /articles/new(.:format) articles#new
edit_article GET /articles/:id/edit(.:format) articles#edit
article GET /articles/:id(.:format) articles#show
PATCH /articles/:id(.:format) articles#update
PUT /articles/:id(.:format) articles#update
DELETE /articles/:id(.:format) articles#destroy
welcome_index GET /welcome/index(.:format) welcome#index
root GET / welcome#index

Ruby on Rails with Sql Server (incompatible character encodings: UTF-8 and ASCII-8BIT)

is there any way to assign the string encoding to UTF-8 in Ruby On Rails 3?
Database Server: Windows Server 2008 R2
PC: Debian Squeeze.
I use Sql Server 2008 with ODBC and found (config/database.yml):
development:
adapter: sqlserver
host: 192.168.0.13\SQLDEVELOPMENT
mode: odbc
dsn: development
database: railsDev
username: developerRails
password: secret
encoding: utf8
gemfile:
...
gem 'tiny_tds'
gem 'activerecord-sqlserver-adapter'
freetds.cfg:
[global]
tds version = 4.2
[development]
host = 192.168.0.13
port = 3341
intance = SQLDEVELOPMENT
tds version = 8.0
My problem is this:
incompatible character encodings: UTF-8 and ASCII-8BIT
Extracted source (around line #28):
26: <td><%= machine.id_maq %></td>
27: <td><%= machine.cod_maq %></td>
28: <td><%= machine.eqp_maq %></td> <!-- string -->
29: <td><%= machine.mar_maq %></td>
30: <td><%= machine.mod_maq %></td>
31: <td><%= machine.ser_maq %></td>
Full trace:
activesupport (3.2.13) lib/active_support/core_ext/string/output_safety.rb:135:in `concat'
activesupport (3.2.13) lib/active_support/core_ext/string/output_safety.rb:135:in `concat'
actionpack (3.2.13) lib/action_view/buffers.rb:11:in `<<'
app/views/machines/index.html.erb:28:in `block in _app_views_machines_index_html_erb__522342465_91242820'
app/views/machines/index.html.erb:23:in `each'
app/views/machines/index.html.erb:23:in `_app_views_machines_index_html_erb__522342465_91242820'
actionpack (3.2.13) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.13) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.13) lib/action_view/template.rb:143:in `render'
actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
actionpack (3.2.13) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.13) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:45:in `render_template'
actionpack (3.2.13) lib/action_view/renderer/template_renderer.rb:18:in `render'
actionpack (3.2.13) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.13) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.13) lib/abstract_controller/rendering.rb:110:in `_render_template'
actionpack (3.2.13) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.13) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.13) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.13) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.13) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.13) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.13) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/home/fhidalgo/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/benchmark.rb:296:in `realtime'
activesupport (3.2.13) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.2.13) lib/action_controller/metal/mime_responds.rb:196:in `respond_to'
app/controllers/machines_controller.rb:8:in `index'
actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.13) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.13) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.13) lib/active_support/callbacks.rb:414:in `_run__557110257__process_action__673728653__callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.13) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.13) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.13) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.13) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.13) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.13) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.13) 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.13) lib/action_dispatch/routing/route_set.rb:612:in `call'
actionpack (3.2.13) 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.13) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.13) 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.13) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.13) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `_run__680852545__call__737805886__callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.13) 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.13) 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.13) lib/action_dispatch/middleware/static.rb:63:in `call'
railties (3.2.13) lib/rails/engine.rb:479:in `call'
railties (3.2.13) lib/rails/application.rb:223:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.13) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/home/fhidalgo/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/fhidalgo/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/fhidalgo/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
This does not help me at all.
I put this: 28: <td><%= machine.eqp_maq.force_encoding("UTF-8") %></td> and works, but I need this throughout the project.
I need to force the strings encoding to UTF-8, is possible?
Please don't use the old 'odbc' connection mode.
When using TinyTds you should use the 'dblib' mode:
development:
adapter: sqlserver
mode: dblib
host: 192.168.0.13\SQLDEVELOPMENT
database: railsDev
username: developerRails
password: secret
See also: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/Using-TinyTds
Make sure all your views, specially the ones that are going to deploy UFT-8 characters are encoded in UTF-8. I solved a similar problem with MySQL that way
I was able to fix the error as follows:
In application.html.erb:
<div class="body">
<%= yield.force_encoding("UTF-8") %>
</div>
Not think it is the best solution but it works.

haml-rails doesn't work in production

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

delayed_job: undefined method `name' for nil:NilClass

I just installed delayed job on my little Rails 3.2 app. Here is the controller where I use it:
require 'waveform'
class MixesController < ApplicationController
def index
end
def new
#mix = Mix.new
end
def create
#mix = Mix.new(params[:mix])
if #mix.save
options = {
method: :rms,
width: 1800,
height: 280,
background_color: "#ffffff",
color: "#3333ff",
force: true,
quiet: true
}
waveform = "./public/waveforms/#{File.basename(#mix.sound_file.to_s, File.extname(#mix.sound_file.to_s))}.png"
::Waveform.new("./public" + #mix.sound_file.to_s, nil).delay.generate(waveform, options)
flash[:success] = "Mix successfully uploaded"
redirect_to mix_url(#mix)
else
render :new
end
end
def show
#mix = Mix.find(params[:id])
end
end
I get an error saying: undefined methodname' for nil:NilClass`, here is the full stack trace:
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:25:in `block in initialize'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `yield'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `default'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `block in initialize'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `yield'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `default'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `block in initialize'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `yield'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `default'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `block in initialize'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `yield'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `default'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:27:in `block in initialize'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `yield'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `default'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `accept'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:447:in `block in dump_ivars'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:445:in `each'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:445:in `dump_ivars'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:124:in `visit_Object'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:102:in `accept'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:434:in `block in emit_coder'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:432:in `each'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:432:in `emit_coder'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:417:in `dump_coder'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:100:in `accept'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:66:in `push'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych.rb:242:in `dump'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/psych/core_ext.rb:14:in `psych_to_yaml'
delayed_job (3.0.3) lib/delayed/backend/base.rb:80:in `payload_object='
activerecord (3.2.3) lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
activerecord (3.2.3) lib/active_record/attribute_assignment.rb:78:in `each'
activerecord (3.2.3) lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
activerecord (3.2.3) lib/active_record/base.rb:498:in `initialize'
delayed_job (3.0.3) lib/delayed/backend/base.rb:28:in `new'
delayed_job (3.0.3) lib/delayed/backend/base.rb:28:in `enqueue'
delayed_job (3.0.3) lib/delayed/message_sending.rb:13:in `method_missing'
app/controllers/mixes_controller.rb:25:in `create'
actionpack (3.2.3) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.3) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.3) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.3) lib/active_support/callbacks.rb:414:in `_run__842168672059661955__process_action__4066633601342968686__callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.3) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.3) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.3) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.3) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.3) lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
activerecord (3.2.3) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.3) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.3) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.3) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.3) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.3) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.3) lib/journey/router.rb:68:in `block in call'
journey (1.0.3) lib/journey/router.rb:56:in `each'
journey (1.0.3) lib/journey/router.rb:56:in `call'
actionpack (3.2.3) lib/action_dispatch/routing/route_set.rb:600:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.3) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `_run__647780415925652457__call__1911592835196459847__callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.3) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.3) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.3) lib/rails/engine.rb:479:in `call'
railties (3.2.3) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/Users/aziz/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Does anyone know why I am getting this error please?
This is happening because the system is trying to turn nil into a value that can be stored in YAML and is failing.
Looking at your code, I expect that is because you are passing a nil object into the variables passed to Waveform.new (the method whose operation is being delayed). The variables passed to new will need to be stored until delayed job is ready to run the process, and I expect they are stored as YAML.
Can you refactor Waveform to either make the second attribute optional (so its value doesn't have to be preserved)
::Waveform.new("./public" + #mix.sound_file.to_s).delay.generate(waveform, options)
or use something else to have the same meaning as nil. For example, pass in the symbol :none. Then the line becomes:
::Waveform.new("./public" + #mix.sound_file.to_s, :none).delay.generate(waveform, options)

CanCan error in Rails 3 app - ArgumentError wrong number of arguments (2 for 1)

I'm attempting to get CanCan working for a few specific actions in my Rails 3 app. I've defined my roles in the Ability.rb class, but something is causing an error in both production and development. Specifically, when I call can? to show/hide a link depending on User role I get the following:
ArgumentError in Higher_eds#show
Showing /Users/me/Desktop/myapp/app/views/higher_eds/_logged_in.html.erb where line #62 raised:
wrong number of arguments (2 for 1)
Can anyone help me figure out what's going on?
I'm getting the error by calling the following in my /higher_eds/_logged_in.html.erb view:
<% if can? :highered_students, #highered %>
<li><%= link_to "Students", highered_students_higher_ed_path, :class=> 'inactive', :remote => true %></li>
<% end %>
In my highered_students action in higher_eds_controller.rb:
def highered_students
#highered = HigherEd.find(params[:id])
#profiles = Profile.where %[higher_ed = ? AND EXTRACT(year FROM college_grad_year) > EXTRACT(year FROM current_date)], #highered.name
respond_to do |format|
format.js { render :layout => nil }
end
end
My Ability.rb:
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new #guest user
if user.role? :highered_admin
can :highered_students, HigherEd
end
if user.role? :admin
can :manage, :all
end
end
end
My full trace:
activerecord (3.0.5) lib/active_record/attribute_methods/query.rb:34:in `attribute?'
activemodel (3.0.5) lib/active_model/attribute_methods.rb:362:in `method_missing'
activerecord (3.0.5) lib/active_record/attribute_methods.rb:46:in `method_missing'
app/models/ability.rb:6:in `initialize'
cancan (1.6.7) lib/cancan/controller_additions.rb:349:in `new'
cancan (1.6.7) lib/cancan/controller_additions.rb:349:in `current_ability'
cancan (1.6.7) lib/cancan/controller_additions.rb:372:in `can?'
actionpack (3.0.5) lib/abstract_controller/helpers.rb:55:in `can?'
app/views/higher_eds/_logged_in.html.erb:62:in `block in _app_views_higher_eds__logged_in_html_erb__1309160371424325548_70132578271280__1361790216911758374'
actionpack (3.0.5) lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
actionpack (3.0.5) lib/action_view/helpers/capture_helper.rb:172:in `with_output_buffer'
actionpack (3.0.5) lib/action_view/helpers/capture_helper.rb:40:in `capture'
actionpack (3.0.5) lib/action_view/helpers/tag_helper.rb:77:in `content_tag'
actionpack (3.0.5) lib/action_view/helpers/record_tag_helper.rb:59:in `content_tag_for'
actionpack (3.0.5) lib/action_view/helpers/record_tag_helper.rb:21:in `div_for'
app/views/higher_eds/_logged_in.html.erb:1:in `_app_views_higher_eds__logged_in_html_erb__1309160371424325548_70132578271280__1361790216911758374'
actionpack (3.0.5) lib/action_view/template.rb:135:in `block in render'
activesupport (3.0.5) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.5) lib/action_view/template.rb:127:in `render'
actionpack (3.0.5) lib/action_view/render/partials.rb:333:in `render_partial'
actionpack (3.0.5) lib/action_view/render/partials.rb:262:in `block in render'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.5) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.5) lib/action_view/render/partials.rb:260:in `render'
actionpack (3.0.5) lib/action_view/render/partials.rb:378:in `_render_partial'
actionpack (3.0.5) lib/action_view/render/rendering.rb:22:in `render'
app/views/higher_eds/show.html.erb:2:in `_app_views_higher_eds_show_html_erb__2358915598045819601_70132577771800__3922384299851769153'
actionpack (3.0.5) lib/action_view/template.rb:135:in `block in render'
activesupport (3.0.5) lib/active_support/notifications.rb:54:in `instrument'
actionpack (3.0.5) lib/action_view/template.rb:127:in `render'
actionpack (3.0.5) lib/action_view/render/rendering.rb:59:in `block in _render_template'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.5) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.5) lib/action_view/render/rendering.rb:56:in `_render_template'
actionpack (3.0.5) lib/action_view/render/rendering.rb:26:in `render'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:115:in `_render_template'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:109:in `render_to_body'
actionpack (3.0.5) lib/action_controller/metal/renderers.rb:47:in `render_to_body'
actionpack (3.0.5) lib/action_controller/metal/compatibility.rb:55:in `render_to_body'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:102:in `render_to_string'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:93:in `render'
actionpack (3.0.5) lib/action_controller/metal/rendering.rb:17:in `render'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.0.5) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/Users/me/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in `realtime'
activesupport (3.0.5) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
activerecord (3.0.5) lib/active_record/railties/controller_runtime.rb:15:in `cleanup_view_runtime'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:39:in actionpack `render'
app/controllers/higher_eds_controller.rb:42:in `show'
actionpack (3.0.5) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.5) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.5) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.5) lib/active_support/callbacks.rb:440:in `_run__4596096755335087880__process_action__1011169593507530898__callbacks'
activesupport (3.0.5) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.5) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.5) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.5) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.5) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.5) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.5) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.5) lib/action_controller/metal.rb:178:in `block in action'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:145:in `optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:492:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.5) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.5) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.5) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.5) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.5) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.5) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.5) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.5) lib/rack/sendfile.rb:106:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.5) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.5) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.5) lib/rack/lock.rb:13:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.5) lib/rack/lock.rb:13:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.5) lib/rails/application.rb:168:in `call'
railties (3.0.5) lib/rails/application.rb:77:in `method_missing'
railties (3.0.5) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.5) lib/rack/content_length.rb:13:in `call'
rack (1.2.5) lib/rack/handler/webrick.rb:52:in `service'
/Users/me/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/me/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/me/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
If I change my Ability.rb logic for checking if a User has a certain role, it works.
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new #guest user
if user.role? == :highered_admin
can :highered_students, HigherEd
end
if user.role? :admin
can :manage, :all
end
end
end
I had it set up for a different role model check.