Rails redirect_to new behaviour with Ruby 2.2 / Rails 4.2?

173 views
Skip to first unread message

Frédéric Champreux

unread,
Feb 13, 2015, 11:02:04 AM2/13/15
to rubyonra...@googlegroups.com
Trying to upgrade from Ruby 2.0 / Rails 4.0 to Ruby 2.2 / Rails 4.2, I
face a surprising error when logging into my application (based on Rails
Tutorial by M. Hartl):

Controller: SessionsController#create
Instruction: redirect_to root_url
Error message: wrong number of arguments (2 for 1)

Here is the sessions controller:

class SessionsController < ApplicationController

def new
end

def create
user = User.find_by_login(params[:session][:login])
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_to root_url
else
flash.now[:error] = 'Invalid login/password combination'
render 'new'
end
end

def destroy
sign_out
redirect_to root_url
end

end

Here is the routes file:

ODQStairs::Application.routes.draw do

resources :requests

#static pages
get '/help', to: "static_pages#help"
get '/about', to: "static_pages#about"
get '/contact', to: "static_pages#contact"

#root definition
root to: "dashboards#home"

#routes
resources :sessions, only: [:new, :create, :destroy]
get '/signin', to: 'sessions#new' , via: :get
match '/signout', to: 'sessions#destroy', via: :delete

resources :parameters_lists do
resources :parameters
end
...

I did not find anything in Rails upgrade guides regarding the
redirect_to function. Your help is welcome! Thanks!

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Feb 13, 2015, 11:20:46 AM2/13/15
to rubyonra...@googlegroups.com
On 13 February 2015 at 16:01, Frédéric Champreux <li...@ruby-forum.com> wrote:
> Trying to upgrade from Ruby 2.0 / Rails 4.0 to Ruby 2.2 / Rails 4.2, I
> face a surprising error when logging into my application (based on Rails
> Tutorial by M. Hartl):
>
> Controller: SessionsController#create
> Instruction: redirect_to root_url
> Error message: wrong number of arguments (2 for 1)

Could you copy/paste the full error message from the terminal please?

Colin

Frédéric Champreux

unread,
Feb 13, 2015, 12:28:20 PM2/13/15
to rubyonra...@googlegroups.com
The full console message is :

ArgumentError (wrong number of arguments (2 for 1)):
app/controllers/sessions_controller.rb:10:in `create'

See the attached screenshot.

Thanks for your help !

Fred

Attachments:
http://www.ruby-forum.com/attachment/10501/Screenshot.jpg

Jason Hobbs

unread,
Feb 13, 2015, 2:55:19 PM2/13/15
to rubyonra...@googlegroups.com
Add gem 'responders' to your Gemfile.
redirect_to was moved to that.

Frederick Cheung

unread,
Feb 13, 2015, 5:23:46 PM2/13/15
to rubyonra...@googlegroups.com
On Friday, February 13, 2015 at 7:55:19 PM UTC, Jason Hobbs wrote:
> Add gem 'responders' to your Gemfile.
> redirect_to was moved to that.

It most certainly wasn't (responders gem is about respond_with/ class level respond_to)

Fred

botp

unread,
Feb 13, 2015, 8:57:56 PM2/13/15
to rubyonra...@googlegroups.com
On Sat, Feb 14, 2015 at 12:01 AM, Frédéric Champreux
<li...@ruby-forum.com> wrote:
> Trying to upgrade from Ruby 2.0 / Rails 4.0 to Ruby 2.2 / Rails 4.2, I
> face a surprising error when logging into my application (based on Rails
> Tutorial by M. Hartl):
>
> Controller: SessionsController#create
> Instruction: redirect_to root_url
> Error message: wrong number of arguments (2 for 1)

probly the redirect_to is not clean. check its code. (compare w the
newly installed railstutorial)
usually when you upgrade rails/ruby to maj ver, youd also want to
upgrade the gems...

kind regards --botp

Colin Law

unread,
Feb 14, 2015, 4:00:07 AM2/14/15
to rubyonra...@googlegroups.com
On 13 February 2015 at 17:27, Frédéric Champreux <li...@ruby-forum.com> wrote:
> The full console message is :
>
> ArgumentError (wrong number of arguments (2 for 1)):
> app/controllers/sessions_controller.rb:10:in `create'
>
> See the attached screenshot.
> ...
> Attachments:
> http://www.ruby-forum.com/attachment/10501/Screenshot.jpg

It would have been better to copy/paste the error from the server
terminal window as I asked, remember many still pay for bandwidth,
particularly on mobile devices.

That is rather odd, can you copy/paste the result of
rake routes
here please.

Assuming that does not show anything odd I would next try to home in
on the exact item that is causing the problem, possibly:
1. comment out the offending line and check that the error moves to
the second redirect_to just below.
2. modify the line first so as to redirect_to a plain string url, if
that fails in the same way it is an issue with redirect_to
3. if 2 now passes then try using root_url with a different function
and see if that passes.

Also possibly useful I think to post Gemfile.lock here.

Colin

Frédéric Champreux

unread,
Feb 14, 2015, 7:30:43 PM2/14/15
to rubyonra...@googlegroups.com
As suggested bopt, I had a look at my gems versions, I actually missed a
few. I updated to the last versions, following gems have been installed:
Installing websocket 1.2.1
Installing selenium-webdriver 2.44.0
Installing bootstrap-will_paginate 0.0.10
Installing sass 3.4.12
Installing annotate 2.6.5
Installing globalid 0.3.3

This solved the issue.

Thanks for your help!

Best regards,

Fred
Reply all
Reply to author
Forward
0 new messages