Ruby on rails 设计注册和登录轨道

Ruby on rails 设计注册和登录轨道,ruby-on-rails,ruby,devise,Ruby On Rails,Ruby,Devise,默认使用design。用户注册后,它会在注册后自动登录。是否仍然可以注册用户而不自动登录并重定向到登录页面?您需要覆盖设计::注册控制器#创建。您可以看到注册是如何工作的 首先,创建designe::RegistrationController的自定义控制器子类 class RegistrationController < Devise::RegistrationsController def create build_resource(sign_up_params)

默认使用design。用户注册后,它会在注册后自动登录。是否仍然可以注册用户而不自动登录并重定向到登录页面?

您需要覆盖
设计::注册控制器#创建
。您可以看到注册是如何工作的

首先,创建designe::RegistrationController的自定义控制器子类

class RegistrationController < Devise::RegistrationsController
  def create
    build_resource(sign_up_params)

    resource.save
    yield resource if block_given?
    if resource.persisted?
      if resource.active_for_authentication?
        set_flash_message! :notice, :signed_up
        respond_with resource, location: root_path # Change this to whatever route your want
      else
        set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
        expire_data_after_sign_in!
        respond_with resource, location: after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      set_minimum_password_length
      respond_with resource
    end
  end 
end
class RegistrationController
然后告诉Desive使用自定义控制器:

design\u用于:用户,:控制器=>{:registrations=>“registrations”}


假设
用户
当然是模型。

我现在得到了这个错误。“app/controllers/registrations\u controller.rb:11:语法错误,意外关键字\u else^”更新了我的答案。答案不是复制粘贴,因为注册后需要设置目标路径。我现在把
根路径
放进去,但要根据需要更改它