Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Syntaxerror - Unexpected '{' in sessionscontroller

I have cloned a quiz app project from this repo: https://github.com/Pk13055/quiz-app

I am trying to run it from my system by using this command:

rails server

But I am getting this error:

/home/laxmanrm/.rvm/gems/ruby-2.6.0/gems/devise-4.3.0/app/controllers/devise/sessions_controller.rb:5: syntax error, unexpected '{', expecting end ...ion only: [:create, :destroy] { request.env["devise.skip_tim... ... ^ /home/laxmanrm/.rvm/gems/ruby-2.6.0/gems/devise-4.3.0/app/controllers/devise/sessions_controller.rb:5: syntax error, unexpected '}', expecting end ..."devise.skip_timeout"] = true } ... ^
Extracted source (around line #5):

  prepend_before_action :allow_params_authentication!, only: :create
  prepend_before_action :verify_signed_out_user, only: :destroy
  prepend_before_action only: [:create, :destroy] { request.env["devise.skip_timeout"] = true }

  # GET /resource/sign_in
  def new

How can I rectify this error and make the application run?

sessions_controller.rb

class Devise::SessionsController < DeviseController
  prepend_before_action :require_no_authentication, only: [:new, :create]
  prepend_before_action :allow_params_authentication!, only: :create
  prepend_before_action :verify_signed_out_user, only: :destroy
  prepend_before_action only: [:create, :destroy] { request.env["devise.skip_timeout"] = true }

  # GET /resource/sign_in
  def new
    self.resource = resource_class.new(sign_in_params)
    clean_up_passwords(resource)
    yield resource if block_given?
    respond_with(resource, serialize_options(resource))
  end
like image 345
Lax_Sam Avatar asked May 02 '19 03:05

Lax_Sam


2 Answers

It seems there's a problem with Ruby 2.5+ and devise: https://github.com/plataformatec/devise/issues/4630.

Apparently devise 4.4.0 has fixed it, but you are using v4.3.0 (check your Gemfile.lock). You need to update it:

bundle update devise
like image 120
CAmador Avatar answered Nov 17 '22 14:11

CAmador


You can use a lamda, in line5

prepend_before_action -> { request.env["devise.skip_timeout"] = true }, only: [:create, :destroy]
like image 27
Luna Lovegood Avatar answered Nov 17 '22 14:11

Luna Lovegood