Problem when migrating from Authlogic to Devise - ruby-on-rails

I referred this Migrating from Authlogic to Devise
and followed it to get the database structure required by devise ready.
However I get this error on my sign_in page
wrong number of arguments (2 for 1)
This is my Request:
{"commit"=>"Sign in","authenticity_token"=>"oWXrE+EdhO4ScuaBzPBqCnpYsal1QcDC483ygVSs0fw=","user"=>{"password"=>"password", "email"=>"email#email.com"}}
I'm using Rails 2.3.8 and hence using Devise v 1.0.
This is my sessions/new view :
<% form_for resource_name, resource, :url => session_path(resource_name) do |f| -%>
<p><%= f.label :email %></p>
<p><%= f.text_field :email %></p>
<p><%= f.label :password %></p>
<p><%= f.password_field :password %></p>
<p><%= f.submit "Sign in" %></p>
<% end -%>
Any ideas to get this to work? Thanks !
EDIT
Here's the stack trace:
ArgumentError (wrong number of arguments (2 for 1)):
devise (1.0.8) lib/devise/models/database_authenticatable.rb:139:in `find_for_authentication'
devise (1.0.8) lib/devise/models/database_authenticatable.rb:117:in `authenticate'
devise (1.0.8) lib/devise/strategies/database_authenticatable.rb:16:in `authenticate!'
warden (1.0.3) lib/warden/strategies/base.rb:53:in `_run!'
warden (1.0.3) lib/warden/proxy.rb:303:in `_run_strategies_for'
warden (1.0.3) lib/warden/proxy.rb:298:in `each'
warden (1.0.3) lib/warden/proxy.rb:298:in `_run_strategies_for'
warden (1.0.3) lib/warden/proxy.rb:271:in `_perform_authentication'
warden (1.0.3) lib/warden/proxy.rb:90:in `authenticate'
devise (1.0.8) lib/devise/controllers/helpers.rb:36:in `authenticate'
devise (1.0.8) app/controllers/sessions_controller.rb:19:in `create'
warden (1.0.3) lib/warden/manager.rb:35:in `call'
warden (1.0.3) lib/warden/manager.rb:34:in `catch'
warden (1.0.3) lib/warden/manager.rb:34:in `call'
Anything to do with warden dependency?

I had the same problem, using warden 0.10.7 and devise 1.0.8
I tried the User.find in the console and was OK.
To fix it, I removed the class method authenticate on my User-Model:
#def self.authenticate(login, pass)
# find(:first, :conditions => ["login = ? AND password = ?", login, sha1(pass)])
#end

The error seems to be occuring in a User.find call, which is strange. Do you have anything that might be overriding the default find method?
Try this in the console and see if you get an error.
User.find(:first, :conditions=>{:email=>'email#email.com'})

Related

Devise session_controller ArgumentError

I created a session_controller to handle token authentication, but I got this error:
Started POST "/users/sign_in" for 127.0.0.1 at 2013-04-29 20:29:44 +0200
Processing by SessionsController#create as */*
Parameters: {"user_login"=>{"login"=>"admin#example.com.", "password"=>"[FILTERED]"}}
Completed 500 Internal Server Error in 1ms
ArgumentError (wrong number of arguments (2 for 1)):
activerecord (3.2.13) lib/active_record/attribute_methods.rb:24:in `[]'
.../bundler/gems/devise-dceb788c6b53/lib/devise.rb:436:in `block (2 levels) in configure_warden!'
warden (1.2.1) lib/warden/session_serializer.rb:35:in `fetch'
warden (1.2.1) lib/warden/proxy.rb:212:in `user'
warden (1.2.1) lib/warden/proxy.rb:318:in `_perform_authentication'
warden (1.2.1) lib/warden/proxy.rb:104:in `authenticate'
warden (1.2.1) lib/warden/proxy.rb:114:in `authenticate?'
.../bundler/gems/devise-dceb788c6b53/app/controllers/devise_controller.rb:124:in `require_no_authentication'
My controller looks like:
class SessionsController < DeviseController
before_filter :ensure_params_exist
respond_to :json
def create
build_resource
resource = User.find_for_database_authentication(:email => params[:user_login][:login])
return invalid_login_attempt unless resource
if resource.valid_password?(params[:user_login][:password])
sign_in("user", resource)
render :json => {:success => true, :auth_token => resource.authentication_token, :email => resource.email}
return
end
invalid_login_attempt
end
And my route file:
devise_for :users, :controllers => {:sessions => "sessions"}
Whats wrong?
Your class declaration does not match Devise namespace:
class SessionsController < Devise::SessionsController

Omniauth-twitter returns 401

Stage:
I have a Rails app, it should authenticate users using their twitter account, so I use Omniauth-Twitter gem.
I have configured one app in dev.twitter.com enabling Sign in with twitter flag and getting consumer_key and consumer_secret.
I was following this guide https://github.com/arunagw/omniauth-twitter#readme
In Rails app, I have configured some files:
config/initializers/omniauth.rb:
Rails.application.config.middleware.use OmniAuth::Builder do
# Twitter consumer data
CONSUMER_KEY='xxxxxxxxxxxxxxxxx'
CONSUMER_SECRET='yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
provider :twitter, CONSUMER_KEY, CONSUMER_SECRET
end
sessions_controller.rb looks like:
class SessionsController < ApplicationController
def create
raise request.env["omniauth.auth"].to_yaml
end
end
applications.html.erb layout:
<div id="user_nav">
<%= link_to "Sign in with Twitter", "/auth/twitter" %>
</div>
So I except that when I clic on Sign in with Twitter link, I raises an exception showing me authentication data or requesting me Twitter autorization.
Problem:
Instead of this, it returns back this:
OAuth::Unauthorized (401 Unauthorized):
oauth (0.4.7) lib/oauth/consumer.rb:216:in `token_request'
oauth (0.4.7) lib/oauth/consumer.rb:136:in `get_request_token'
omniauth-oauth (1.0.1) lib/omniauth/strategies/oauth.rb:29:in `request_phase'
omniauth-twitter (0.0.15) lib/omniauth/strategies/twitter.rb:63:in `request_phase'
omniauth (1.1.3) lib/omniauth/strategy.rb:207:in `request_call'
omniauth (1.1.3) lib/omniauth/strategy.rb:174:in `call!'
omniauth (1.1.3) lib/omniauth/strategy.rb:157:in `call'
omniauth (1.1.3) lib/omniauth/builder.rb:48:in `call'
What is wrong here?

Strange rails error

Everything in my app was working fine, walked away for a few hours and came back to this...
Psych::SyntaxError in Home#index
Showing /Users/nelsonkeating/Desktop/ReminDeal/app/views/layouts/_navigation.html.erb where line #16 raised:
couldn't parse YAML at line 13 column 2
Extracted source (around line #16):
13: <div class="testform">
14: <%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
15:
16: <%= f.input :email, :required => false, :autofocus => true, :label => false, :placeholder => 'Email' %>
17: <%= f.input :password, :required => false, :label => false, :placeholder => 'Password' %>
18: <%= f.button :submit, "Sign in", :class =>'btn btn-info' %>
19: <%= link_to 'Sign up', new_user_registration_path, :class=>'btn btn-success' %>
Trace of template inclusion: app/views/layouts/application.html.erb
Rails.root: /Users/nelsonkeating/Desktop/ReminDeal
Application Trace | Framework Trace | Full Trace
/Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:148:in `parse'
/Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:148:in `parse_stream'
/Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:119:in `parse'
/Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:106:in `load'
/Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:205:in `load_file'
/gems/i18n-0.6.0/lib/i18n/backend/base.rb:171:in `load_yml'
/gems/i18n-0.6.0/lib/i18n/backend/base.rb:157:in `load_file'
/gems/i18n-0.6.0/lib/i18n/backend/base.rb:15:in `block in load_translations'
/gems/i18n-0.6.0/lib/i18n/backend/base.rb:15:in `each'
/gems/i18n-0.6.0/lib/i18n/backend/base.rb:15:in `load_translations'
/gems/i18n-0.6.0/lib/i18n/backend/simple.rb:57:in `init_translations'
/gems/i18n-0.6.0/lib/i18n/backend/simple.rb:71:in `lookup'
/gems/i18n-0.6.0/lib/i18n/backend/base.rb:26:in `translate'
/gems/i18n-0.6.0/lib/i18n.rb:156:in `block in translate'
/gems/i18n-0.6.0/lib/i18n.rb:152:in `catch'
/gems/i18n-0.6.0/lib/i18n.rb:152:in `translate'
/gems/simple_form-2.0.2/lib/simple_form/inputs/base.rb:174:in `translate'
/gems/simple_form-2.0.2/lib/simple_form/components/hints.rb:8:in `hint'
/gems/simple_form-2.0.2/lib/simple_form/wrappers/single.rb:12:in `render'
/gems/simple_form-2.0.2/lib/simple_form/wrappers/many.rb:29:in `block in render'
/gems/simple_form-2.0.2/lib/simple_form/wrappers/many.rb:27:in `each'
/gems/simple_form-2.0.2/lib/simple_form/wrappers/many.rb:27:in `render'
/gems/simple_form-2.0.2/lib/simple_form/wrappers/many.rb:29:in `block in render'
/gems/simple_form-2.0.2/lib/simple_form/wrappers/many.rb:27:in `each'
/gems/simple_form-2.0.2/lib/simple_form/wrappers/many.rb:27:in `render'
/gems/simple_form-2.0.2/lib/simple_form/wrappers/root.rb:15:in `render'
/gems/simple_form-2.0.2/lib/simple_form/form_builder.rb:115:in `input'
app/views/layouts/_navigation.html.erb:16:in `block in _app_views_layouts__navigation_html_erb__200588386938644858_70171278998500'
/gems/actionpack-3.2.3/lib/action_view/helpers/capture_helper.rb:40:in `block in capture'
/gems/actionpack-3.2.3/lib/action_view/helpers/capture_helper.rb:187:in `with_output_buffer'
/gems/actionpack-3.2.3/lib/action_view/helpers/capture_helper.rb:40:in `capture'
/gems/actionpack-3.2.3/lib/action_view/helpers/form_helper.rb:606:in `fields_for'
/gems/client_side_validations-3.1.4/lib/client_side_validations/action_view/form_helper.rb:45:in `fields_for'
/gems/actionpack-3.2.3/lib/action_view/helpers/form_helper.rb:377:in `form_for'
/gems/client_side_validations-3.1.4/lib/client_side_validations/action_view/form_helper.rb:28:in `form_for'
/gems/simple_form-2.0.2/lib/simple_form/action_view_extensions/form_helper.rb:33:in `block in simple_form_for'
/gems/simple_form-2.0.2/lib/simple_form/action_view_extensions/form_helper.rb:51:in `with_simple_form_field_error_proc'
/gems/simple_form-2.0.2/lib/simple_form/action_view_extensions/form_helper.rb:32:in `simple_form_for'
app/views/layouts/_navigation.html.erb:14:in `_app_views_layouts__navigation_html_erb__200588386938644858_70171278998500'
/gems/actionpack-3.2.3/lib/action_view/template.rb:143:in `block in render'
/gems/activesupport-3.2.3/lib/active_support/notifications.rb:125:in `instrument'
/gems/actionpack-3.2.3/lib/action_view/template.rb:141:in `render'
/gems/actionpack-3.2.3/lib/action_view/renderer/partial_renderer.rb:265:in `render_partial'
/gems/actionpack-3.2.3/lib/action_view/renderer/partial_renderer.rb:238:in `block in render'
/gems/actionpack-3.2.3/lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
/gems/activesupport-3.2.3/lib/active_support/notifications.rb:123:in `block in instrument'
/gems/activesupport-3.2.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/gems/activesupport-3.2.3/lib/active_support/notifications.rb:123:in `instrument'
/gems/actionpack-3.2.3/lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
/gems/actionpack-3.2.3/lib/action_view/renderer/partial_renderer.rb:237:in `render'
/gems/actionpack-3.2.3/lib/action_view/renderer/renderer.rb:41:in `render_partial'
/gems/actionpack-3.2.3/lib/action_view/helpers/rendering_helper.rb:27:in `render'
app/views/layouts/application.html.erb:20:in `_app_views_layouts_application_html_erb___581424401402979334_70171303782600'
/gems/actionpack-3.2.3/lib/action_view/template.rb:143:in `block in render'
/gems/activesupport-3.2.3/lib/active_support/notifications.rb:125:in `instrument'
/gems/actionpack-3.2.3/lib/action_view/template.rb:141:in `render'
/gems/actionpack-3.2.3/lib/action_view/renderer/template_renderer.rb:59:in `render_with_layout'
/gems/actionpack-3.2.3/lib/action_view/renderer/template_renderer.rb:45:in `render_template'
/gems/actionpack-3.2.3/lib/action_view/renderer/template_renderer.rb:18:in `render'
/gems/actionpack-3.2.3/lib/action_view/renderer/renderer.rb:36:in `render_template'
/gems/actionpack-3.2.3/lib/action_view/renderer/renderer.rb:17:in `render'
/gems/actionpack-3.2.3/lib/abstract_controller/rendering.rb:110:in `_render_template'
/gems/actionpack-3.2.3/lib/action_controller/metal/streaming.rb:225:in `_render_template'
/gems/actionpack-3.2.3/lib/abstract_controller/rendering.rb:103:in `render_to_body'
/gems/actionpack-3.2.3/lib/action_controller/metal/renderers.rb:28:in `render_to_body'
/gems/actionpack-3.2.3/lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
/gems/actionpack-3.2.3/lib/abstract_controller/rendering.rb:88:in `render'
/gems/actionpack-3.2.3/lib/action_controller/metal/rendering.rb:16:in `render'
/gems/actionpack-3.2.3/lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
/gems/activesupport-3.2.3/lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/benchmark.rb:310:in `realtime'
/gems/activesupport-3.2.3/lib/active_support/core_ext/benchmark.rb:5:in `ms'
/gems/actionpack-3.2.3/lib/action_controller/metal/instrumentation.rb:40:in `block in render'
/gems/actionpack-3.2.3/lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
/gems/activerecord-3.2.3/lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
/gems/actionpack-3.2.3/lib/action_controller/metal/instrumentation.rb:39:in `render'
/gems/actionpack-3.2.3/lib/action_controller/metal/implicit_render.rb:10:in `default_render'
/gems/actionpack-3.2.3/lib/action_controller/metal/implicit_render.rb:5:in `send_action'
/gems/actionpack-3.2.3/lib/abstract_controller/base.rb:167:in `process_action'
/gems/actionpack-3.2.3/lib/action_controller/metal/rendering.rb:10:in `process_action'
/gems/actionpack-3.2.3/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:425:in `_run__3144154735564117921__process_action__4375222825164767808__callbacks'
/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:405:in `__run_callback'
/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
/gems/actionpack-3.2.3/lib/abstract_controller/callbacks.rb:17:in `process_action'
/gems/actionpack-3.2.3/lib/action_controller/metal/rescue.rb:29:in `process_action'
/gems/actionpack-3.2.3/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
/gems/activesupport-3.2.3/lib/active_support/notifications.rb:123:in `block in instrument'
/gems/activesupport-3.2.3/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/gems/activesupport-3.2.3/lib/active_support/notifications.rb:123:in `instrument'
/gems/actionpack-3.2.3/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
/gems/actionpack-3.2.3/lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
/gems/activerecord-3.2.3/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/gems/actionpack-3.2.3/lib/abstract_controller/base.rb:121:in `process'
/gems/actionpack-3.2.3/lib/abstract_controller/rendering.rb:45:in `process'
/gems/actionpack-3.2.3/lib/action_controller/metal.rb:203:in `dispatch'
/gems/actionpack-3.2.3/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
/gems/actionpack-3.2.3/lib/action_controller/metal.rb:246:in `block in action'
/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:73:in `call'
/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:36:in `call'
/gems/journey-1.0.3/lib/journey/router.rb:68:in `block in call'
/gems/journey-1.0.3/lib/journey/router.rb:56:in `each'
/gems/journey-1.0.3/lib/journey/router.rb:56:in `call'
/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:600:in `call'
/gems/client_side_validations-3.1.4/lib/client_side_validations/middleware.rb:18:in `call'
/gems/warden-1.1.1/lib/warden/manager.rb:35:in `block in call'
/gems/warden-1.1.1/lib/warden/manager.rb:34:in `catch'
/gems/warden-1.1.1/lib/warden/manager.rb:34:in `call'
/gems/actionpack-3.2.3/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
/gems/rack-1.4.1/lib/rack/etag.rb:23:in `call'
/gems/rack-1.4.1/lib/rack/conditionalget.rb:25:in `call'
/gems/actionpack-3.2.3/lib/action_dispatch/middleware/head.rb:14:in `call'
/gems/actionpack-3.2.3/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
/gems/actionpack-3.2.3/lib/action_dispatch/middleware/flash.rb:242:in `call'
/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in `context'
/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in `call'
/gems/actionpack-3.2.3/lib/action_dispatch/middleware/cookies.rb:338:in `call'
/gems/activerecord-3.2.3/lib/active_record/query_cache.rb:64:in `call'
/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in `call'
/gems/actionpack-3.2.3/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:405:in `_run__2947535173615619242__call__2415189830075756674__callbacks'
/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:405:in `__run_callback'
/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
/gems/activesupport-3.2.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
/gems/actionpack-3.2.3/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/gems/actionpack-3.2.3/lib/action_dispatch/middleware/reloader.rb:65:in `call'
/gems/actionpack-3.2.3/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
/gems/actionpack-3.2.3/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
/gems/actionpack-3.2.3/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
/gems/railties-3.2.3/lib/rails/rack/logger.rb:26:in `call_app'
/gems/railties-3.2.3/lib/rails/rack/logger.rb:16:in `call'
/gems/actionpack-3.2.3/lib/action_dispatch/middleware/request_id.rb:22:in `call'
/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
/gems/rack-1.4.1/lib/rack/runtime.rb:17:in `call'
/gems/activesupport-3.2.3/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
/gems/rack-1.4.1/lib/rack/lock.rb:15:in `call'
/gems/actionpack-3.2.3/lib/action_dispatch/middleware/static.rb:62:in `call'
/gems/railties-3.2.3/lib/rails/engine.rb:479:in `call'
/gems/railties-3.2.3/lib/rails/application.rb:220:in `call'
/gems/rack-1.4.1/lib/rack/content_length.rb:14:in `call'
/gems/railties-3.2.3/lib/rails/rack/log_tailer.rb:14:in `call'
/gems/thin-1.3.1/lib/thin/connection.rb:80:in `block in pre_process'
/gems/thin-1.3.1/lib/thin/connection.rb:78:in `catch'
/gems/thin-1.3.1/lib/thin/connection.rb:78:in `pre_process'
/gems/thin-1.3.1/lib/thin/connection.rb:53:in `process'
/gems/thin-1.3.1/lib/thin/connection.rb:38:in `receive_data'
/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
/gems/thin-1.3.1/lib/thin/backends/base.rb:61:in `start'
/gems/thin-1.3.1/lib/thin/server.rb:159:in `start'
/gems/rack-1.4.1/lib/rack/handler/thin.rb:13:in `run'
/gems/rack-1.4.1/lib/rack/server.rb:265:in `start'
/gems/railties-3.2.3/lib/rails/commands/server.rb:70:in `start'
/gems/railties-3.2.3/lib/rails/commands.rb:55:in `block in '
/gems/railties-3.2.3/lib/rails/commands.rb:50:in `tap'
/gems/railties-3.2.3/lib/rails/commands.rb:50:in `'
script/rails:6:in `require'
script/rails:6:in `'
Request
Parameters:
None
Show session dump
Show env dump
Response
Headers:
None
Heres the entire _navigation file..
<ul class="nav">
<span class="brand span" href="#">
<%= link_to logo, root_path %>
</span>
<div class="span6 pull-right" id="nav-cont">
<% if user_signed_in? %>
<li>
<div class="logout1">
<%= link_to 'Logout', destroy_user_session_path, :method=>'delete', :class=>'btn btn-inverse' %>
</div>
</li>
<% else %>
<div class="testform">
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
<%= f.input :email, :required => false, :autofocus => true, :label => false, :placeholder => 'Email' %>
<%= f.input :password, :required => false, :label => false, :placeholder => 'Password' %>
<%= f.button :submit, "Sign in", :class =>'btn btn-info' %>
<%= link_to 'Sign up', new_user_registration_path, :class=>'btn btn-success' %>
</div>
<% end %>
<% end %>
</div>
en.yml
# Sample localization file for English. Add more files in this directory for locales.
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
en:
hello: "Hello world"
database.yml
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
devise.en.yml
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
en:
errors:
messages:
expired: "has expired, please request a new one"
not_found: "not found"
already_confirmed: "was already confirmed, please try signing in"
not_locked: "was not locked"
not_saved:
one: "1 error prohibited this %{resource} from being saved:"
:"%{count} errors prohibited this %{resource} from being saved:"
devise:
failure:
already_authenticated: 'You are already signed in.'
unauthenticated: 'You need to sign in or sign up before continuing.'
unconfirmed: 'You have to confirm your account before continuing.'
locked: 'Your account is locked.'
invalid: 'Invalid email or password.'
invalid_token: 'Invalid authentication token.'
timeout: 'Your session expired, please sign in again to continue.'
inactive: 'Your account was not activated yet.'
sessions:
signed_in: 'Signed in successfully.'
signed_out: 'Signed out successfully.'
passwords:
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
updated: 'Your password was changed successfully. You are now signed in.'
updated_not_active: 'Your password was changed successfully.'
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
confirmations:
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
send_paranoid_instructions: 'If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
confirmed: 'Your account was successfully confirmed. You are now signed in.'
registrations:
signed_up: 'Welcome! You have signed up successfully.'
signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
updated: 'You updated your account successfully.'
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
unlocks:
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
omniauth_callbacks:
success: 'Successfully authenticated from %{kind} account.'
failure: 'Could not authenticate you from %{kind} because "%{reason}".'
mailer:
confirmation_instructions:
subject: 'Confirmation instructions'
reset_password_instructions:
subject: 'Reset password instructions'
unlock_instructions:
subject: 'Unlock Instructions'
NEW ERROR
ArgumentError in Home#index
Showing /Users/nelsonkeating/Desktop/ReminDeal/app/views/layouts/_navigation.html.erb where line #16 raised:
syntax error on line 12, col -1: ` devise:
failure:
already_authenticated: 'You are already signed in.'
unauthenticated: 'You need to sign in or sign up before continuing.'
unconfirmed: 'You have to confirm your account before continuing.'
locked: 'Your account is locked.'
invalid: 'Invalid email or password.'
invalid_token: 'Invalid authentication token.'
timeout: 'Your session expired, please sign in again to continue.'
inactive: 'Your account was not activated yet.'
sessions:
signed_in: 'Signed in successfully.'
signed_out: 'Signed out successfully.'
passwords:
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
updated: 'Your password was changed successfully. You are now signed in.'
updated_not_active: 'Your password was changed successfully.'
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
confirmations:
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
send_paranoid_instructions: 'If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
confirmed: 'Your account was successfully confirmed. You are now signed in.'
registrations:
signed_up: 'Welcome! You have signed up successfully.'
signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
updated: 'You updated your account successfully.'
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
unlocks:
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
omniauth_callbacks:
success: 'Successfully authenticated from %{kind} account.'
failure: 'Could not authenticate you from %{kind} because "%{reason}".'
mailer:
confirmation_instructions:
subject: 'Confirmation instructions'
reset_password_instructions:
subject: 'Reset password instructions'
unlock_instructions:
subject: 'Unlock Instructions''
The "couldn't parse YAML" error suggests that there is an issue with the formatting of a YAML file.
In your case, there's a formatting error in your devise.en.yml:
not_saved:
one: "1 error prohibited this %{resource} from being saved:"
:"%{count} errors prohibited this %{resource} from being saved:"
Before the : on the last line, it is missing a key. Perhaps this was accidentally deleted somehow? In other devise translation files, I typically see the key "other".
not_saved:
one: "1 error prohibited this %{resource} from being saved:"
other: "%{count} errors prohibited this %{resource} from being saved:"
Try
en:
- hello: "Hello world"
Replaced all YML files with previous versions.. if you have a problem like this there is probably and extra character or space buried in one of those files.. can be impossible to find, recommend replacing files if they have not been modified.
I had this error and it turned out to be a tab character that was present on a blank line. Invisible, but apparently caused the parser to choke.
To find it in vim I did a search for tab chars:
/\t

Rails: Action error in production but not in development

Can anyone explain why I keep getting an error in production but not in development? Relevant parts:
get: /user/logout
ActionController::RoutingError (uninitialized constant User::SessionController):
activesupport/lib/active_support/inflector/methods.rb:229:in `block in constantize'
activesupport/lib/active_support/inflector/methods.rb:228:in `each'
activesupport/lib/active_support/inflector/methods.rb:228:in `constantize'
actionpack/lib/action_dispatch/routing/route_set.rb:69:in `controller_reference'
actionpack/lib/action_dispatch/routing/route_set.rb:54:in `controller'
actionpack/lib/action_dispatch/routing/route_set.rb:32:in `call'
journey/lib/journey/router.rb:68:in `block in call'
journey/lib/journey/router.rb:56:in `each'
journey/lib/journey/router.rb:56:in `call'
actionpack/lib/action_dispatch/routing /route_set.rb:600:in `call'
omniauth/lib/omniauth/strategy.rb:177:in `call!'
omniauth/lib/omniauth/strategy.rb:157:in `call'
omniauth/lib/omniauth/builder.rb:48:in `call'
airbrake/lib/airbrake/rack.rb:27:in `call'
Routes:
Application1::Application.routes.draw do
match('/auth/:provider/callback' => 'session#create', :format => false)
root(:to => 'blog/archives#index', :format => false)
namespace(:user) do
match('/logout' => 'session#destroy', :format => false)
end
namespace(:blog) do
match('/archive/:slug' => 'archive#show', :format => false)
constraints(:page => /page\d+/) do
match('/archives/:page' => 'archives#index', :format => false)
end
end
end
I am using Rails 3.2.3 with the latest Omniauth.
You have created a namespace user and therefore you should place the session controller that defines the destroy action in this path:
/app/controllers/user/session_controller.rb
Then you can do stuff like:
Create a file in /app/controller/user/base_controller.rb that defines this:
class User::BaseController < ApplicationController
# Whatever you want here
end
And define the sessions controller located in /app/controllers/user/session_controller.rb as:
class Users::SessionsController < User::BaseController
def destroy
# whatever you want destroy to do..
end
end
Read this for more documentation about namespaces and routing.

Rails: Absolutely stumped with delayed_job. Not receiving arguments anywhere

I'm trying to send mail in a Rails 3 application using collectiveidea's delayed_job. If I try to send mail regularly (.deliver) it works fine, but as soon as I switch to delayed job, things fall to pieces.
The standard error I get in the delayed_job mysql table is:
{undefined method `name' for
nil:NilClass...
where 'name' is the first argument in the mailer's view (#contact.name). This works fine if I take delayed_job out again.
If I remove all references to #contact in the view, I get
{A sender (Return-Path, Sender or
From) required to send a message
In short, it doesn't seem to be understanding any arguments at all.
All relevant code below - if anyone has any suggestions for this it would be very appreciated
CONTROLLER
def sendmail
#contact = Contact.new(params[:contact])
if #contact.save
ContactMailer.delay.contact_mail(#contact)
flash[:notice] = 'Your message has been successfully sent'
redirect_to root_path
else
render :action => 'index'
end
end
MAILER:
class ContactMailer < ActionMailer::Base
default :from => "my#email.address"
def contact_mail(contact)
#contact = contact
mail(:to => 'my#email.address', :subject => 'Contact Form Query', :from => 'my#email.address', :content_type => 'text/plain')
end
handle_asynchronously :contact_mail, :run_at => Proc.new { 2.seconds.from_now }
end
MAILER VIEW:
You have received a new query:
-----------------------------------
<%= #contact.name %>
<%= #contact.business %>
<%= #contact.phone %>
-----------------------
<%= #contact.message %>
-----------------------
INITIALIZER:
Delayed::Worker.destroy_failed_jobs = false
Delayed::Worker.max_run_time = 5.weeks
And finally, the full error message:
{undefined method `name' for nil:NilClass
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/whiny_nil.rb:48:in `method_missing'
/Users/john/Websites/Rails/InDevelopment/connectted/app/views/contact_mailer/contact_mail.html.erb:4:in `_app_views_contact_mailer_contact_mail_html_erb___3386534441642202773_2166008980__4301703149293725172'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_view/template.rb:135:in `block in render'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/notifications.rb:54:in `instrument'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_view/template.rb:127:in `render'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_view/render/rendering.rb:59:in `block in _render_template'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/notifications.rb:52:in `block in instrument'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/notifications.rb:52:in `instrument'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_view/render/rendering.rb:56:in `_render_template'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_view/render/rendering.rb:26:in `render'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/abstract_controller/rendering.rb:114:in `_render_template'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/abstract_controller/rendering.rb:108:in `render_to_body'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/abstract_controller/rendering.rb:101:in `render_to_string'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/abstract_controller/rendering.rb:92:in `render'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/deprecated_api.rb:111:in `render'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/old_api.rb:210:in `block in create_parts'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/old_api.rb:208:in `each'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/old_api.rb:208:in `create_parts'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/deprecated_api.rb:143:in `create_parts'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/old_api.rb:77:in `process'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/base.rb:446:in `process'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/base.rb:441:in `initialize'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/base.rb:425:in `new'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/actionmailer-3.0.0/lib/action_mailer/base.rb:425:in `method_missing'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/performable_mailer.rb:6:in `perform'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/backend/base.rb:83:in `invoke_job'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:119:in `block (2 levels) in run'
/Users/john/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/timeout.rb:57:in `timeout'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed
/worker.rb:119:in `block in run'
/Users/john/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:118:in `run'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:176:in `reserve_and_run_one_job'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:103:in `block in work_off'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:102:in `times'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:102:in `work_off'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:77:in `block (2 levels) in start'
/Users/john/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:76:in `block in start'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:73:in `loop'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/worker.rb:73:in `start'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:100:in `run'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:79:in `block in run_process'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/application.rb:250:in `call'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/application.rb:250:in `block in start_proc'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/daemonize.rb:199:in `call'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/daemonize.rb:199:in `call_as_daemon'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/application.rb:254:in `start_proc'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/application.rb:294:in `start'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/controller.rb:70:in `run'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons.rb:193:in `block in run_proc'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/cmdline.rb:112:in `call'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons/cmdline.rb:112:in `catch_exceptions'
/Users/john/.rvm/gems/ruby-1.9.2-p0/gems/daemons-1.1.0/lib/daemons.rb:192:in `run_proc'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:78:in `run_process'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:72:in `block in daemonize'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:70:in `times'
/Users/john/.rvm/gems/ruby-1.9.2-p0/bundler/gems/delayed_job-c933ffcd776a/lib/delayed/command.rb:70:in `daemonize'
script/delayed_job:5:in `<main>' |
The issue is with the code in your mailer taking the object instead of the objects id:
def contact_mail(contact)
#contact = contact
mail(:to => 'my#email.address', :subject => 'Contact Form Query', :from => 'my#email.address', :content_type => 'text/plain')
end
You should change that to this:
def contact_mail(contact_id)
#contact = Contact.find(contact_id)
mail(:to => 'my#email.address', :subject => 'Contact Form Query', :from => 'my#email.address', :content_type => 'text/plain')
end
Never pass the actual objects to your mailer. Simply pass the id's and retrieve them upon processing.
I had this same problem, and fixed it by moving all the attributes into instance variables. So, in the view:
<%= #contact.name %>
<%= #contact.business %>
<%= #contact.phone %>
becomes:
<%= #name %>
<%= #business %>
<%= #phone %>
and I just looked up the instance variables in the mailer method. So, in the mailer:
def contact_mail(contact)
#contact = contact
mail(:to => 'my#email.address', :subject => 'Contact Form Query', :from => 'my#email.address', :content_type => 'text/plain')
end
becomes:
def contact_mail(contact)
#name = contact.name
#business = contact.business
#phone = contact.phone
mail(:to => 'my#email.address', :subject => 'Contact Form Query', :from => 'my#email.address', :content_type => 'text/plain')
end
Why is it not working? Not sure, I imagine it has to do with some ActionMailer voodoo.
How to get it working? Abstract out the delayed job pieces into another class. Have the method that is delayed do nothing more than send them email; meaning that the rendering of the email is done in real time, but the sending of it is delayed. This should get around your problem and accomplish the asynchronous sending of emails.
Hey this might be far off, but you're not sending any params to your MAILER. Here's a copy of my referred_email.rb I keep in my lib/ dir. I call it with delayed_job:
#my controller
Delayed::Job.enqueue ReferredEmail.new(params[:subject], params[:editor1])
#Reffered_Email.rb
class ReferredEmail < Struct.new(:subject, :editor1)
def perform
(CardReferral.all.map(&:email) - CardSignup.all.map(&:email)).each do |cf|
#cf = CardReferral.find_by_email(cf)
Notifier.deliver_referred_magic_email(User.find(#cf.user_id), #cf.email, #cf.name, #cf.message, subject, editor1)
end
end
end
It seems like you are using both:
ContactMailer.delay.contact_mail(#contact)
and
handle_asynchronously :contact_mail, :run_at => Proc.new { 2.seconds.from_now }
which you should only do one or the other. Try removing the handle_asynchronously and see if that fixes the problem.

Resources