Rails:Syntaxerror-会话控制器

时间:2019-05-02 03:59:11

标签: ruby-on-rails

我已从此仓库中克隆了一个测验应用项目:https://github.com/Pk13055/quiz-app

我正在尝试使用以下命令从系统中运行它:

rails server

但是我收到此错误:

/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

如何纠正此错误并使应用程序运行?

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

2 个答案:

答案 0 :(得分:2)

似乎Ruby 2.5+的设计存在问题:https://github.com/plataformatec/devise/issues/4630

显然devise 4.4.0已修复它,但是您正在使用v4.3.0(请检查Gemfile.lock)。您需要更新它:

bundle update devise

答案 1 :(得分:0)

您可以在第5行中使用lamda

prepend_before_action -> { request.env["devise.skip_timeout"] = true }, only: [:create, :destroy]