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!
On 13 February 2015 at 16:01, Frédéric Champreux [email protected]
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?
On Sat, Feb 14, 2015 at 12:01 AM, Frédéric Champreux [email protected] 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…
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:
comment out the offending line and check that the error moves to
the second redirect_to just below.
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
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.
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.