【问题标题】:devise confirmable routing - rails 4设计可确认的路由 - rails 4
【发布时间】:2015-06-28 20:15:19
【问题描述】:

我是 Rails 新手,我们将不胜感激任何建议和帮助。

我目前正在使用可确认的设计

当用户第一次注册时:

  • 重定向到 localhost:3000 的应用程序根目录
  • Flash 通知显示“带有确认链接的消息已发送到您的电子邮件地址。请打开链接以激活您的帐户。”

到目前为止一切顺利。

我试图在用户注册时将他们重定向到不同的页面 但不确定如何 - 任何建议将不胜感激

application_controller.rb

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  before_filter :configure_permitted_parameters, if: :devise_controller?

  protected
  def after_sign_in_path_for(resources)
    if userr_signed_in?
      dashboard_path
    elsif usera_signed_in?
      admin_path
    else
      dashboardj_path
    end
  end

  def after_sign_out_path_for(resources)
    new_feedback_path
  end

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:email) }
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:category_businesstype_id, :firstname, :lastname, :companyname, :email, :password, :category_role_id, :staff, :number, :hear, :city, :category_qualification_id, :language, :category_careerlevel_id, :desiredjob, :category_distance_id, :category_cvpreference_id, :category_joboption_id, :preferedlocation, :category_notice_id, :category_country_id, :category_positiontype_id ) }
  end
end

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 devise


    【解决方案1】:

    根据您的情况,您希望在特定路径上注册后重定向用户。为此,您需要覆盖 after_sign_up_path 而不是 after_sign_in_path。

    在应用程序控制器中你应该有这个方法

    def after_sign_up_path_for(resource)
      after_registration_path // Your path should goes here
    end
    

    只有当您在注册后立即尝试将用户实际登录到您的系统时,才能使用 After sign_in 路径。在这里你只需要重定向一个用户。

    【讨论】:

    • @ARTLoe 我的荣幸 :)
    猜你喜欢
    • 1970-01-01
    • 2012-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多