Ruby on rails 从设备确认更改闪光错误

Ruby on rails 从设备确认更改闪光错误,ruby-on-rails,devise,devise-confirmable,Ruby On Rails,Devise,Devise Confirmable,我使用Desive中的这个功能,设置用户创建一个没有密码的帐户的能力,但在以后确认时设置 但是,摘录中显示了错误。我想更换控制器,就像Rails中常见的flash一样 我该怎么做 我覆盖的控制器如下所示: # app/controllers/confirmations_controller.rb class ConfirmationsController < Devise::ConfirmationsController layout "login" # Remove the

我使用Desive中的这个功能,设置用户创建一个没有密码的帐户的能力,但在以后确认时设置

但是,
摘录中显示了错误。我想更换控制器,就像Rails中常见的
flash
一样

我该怎么做

我覆盖的控制器如下所示:

# app/controllers/confirmations_controller.rb
class ConfirmationsController < Devise::ConfirmationsController

  layout "login"

  # Remove the first skip_before_filter (:require_no_authentication) if you
  # don't want to enable logged users to access the confirmation page.
  skip_before_filter :require_no_authentication
  skip_before_filter :authenticate_user!

  # PUT /resource/confirmation
  def update
    with_unconfirmed_confirmable do
      if @confirmable.has_no_password?
        @confirmable.attempt_set_password(params[:user])
        if @confirmable.valid?
          do_confirm
        else
          do_show
          @confirmable.errors.clear #so that we wont render :new
        end
      else
        self.class.add_error_on(self, :email, :password_allready_set)
      end
    end

    if !@confirmable.errors.empty?
      render 'devise/confirmations/new' #Change this if you don't have the views on default path
    end
  end

  # GET /resource/confirmation?confirmation_token=abcdef
  def show
    with_unconfirmed_confirmable do
      if @confirmable.has_no_password?
        do_show
      else
        do_confirm
      end
    end
    if !@confirmable.errors.empty?
      self.resource = @confirmable
      render 'devise/confirmations/new' #Change this if you don't have the views on default path 
    end
  end

  protected

  def with_unconfirmed_confirmable
    @confirmable = User.find_or_initialize_with_error_by(:confirmation_token, params[:confirmation_token])
    if !@confirmable.new_record?
      @confirmable.only_if_unconfirmed {yield}
    end
  end

  def do_show
    @confirmation_token = params[:confirmation_token]
    @requires_password = true
    self.resource = @confirmable
    render 'devise/confirmations/show' #Change this if you don't have the views on default path
  end

  def do_confirm
    @confirmable.confirm!
    set_flash_message :notice, :confirmed
    sign_in_and_redirect(resource_name, @confirmable)
  end
end
#app/controllers/confirmations_controller.rb
类确认控制器<设计::确认控制器
布局“登录”
#如果需要,请删除第一个“在\u之前跳过\u”筛选器(:要求\u无\u身份验证)
#不希望允许已登录的用户访问确认页面。
在\u筛选器之前跳过\u:要求\u无\u身份验证
跳过\u过滤器之前的\u:验证\u用户!
#投入/资源/确认
def更新
带未确认的可确认的do
如果@confirmable.has\u没有密码?
@可确认。尝试设置密码(参数[:用户])
如果@confirmable.valid?
你确认吗
其他的
秀
@confirmable.errors.clear#这样我们就不会渲染:新
结束
其他的
self.class.add\u error\u on(self,:email,:password\u allready\u set)
结束
结束
如果@可确认。错误。空?
呈现“设计/确认/新建”#如果您没有默认路径上的视图,请更改此选项
结束
结束
#获取/资源/确认?确认令牌=abcdef
def秀
带未确认的可确认的do
如果@confirmable.has\u没有密码?
秀
其他的
你确认吗
结束
结束
如果@可确认。错误。空?
self.resource=@confirmable
呈现“设计/确认/新建”#如果您没有默认路径上的视图,请更改此选项
结束
结束
受保护的
带有未确认的def可确认的def
@confirmable=用户。通过(:confirmation\u token,params[:confirmation\u token])查找或初始化带有错误的\u
如果@可确认的新记录?
@可确认。仅当_未确认{yield}
结束
结束
def do_show
@确认令牌=参数[:确认令牌]
@需要\u password=true
self.resource=@confirmable
呈现“设计/确认/显示”#如果您没有默认路径上的视图,请更改此选项
结束
请确认
@确认,确认!
设置\u闪烁\u消息:通知,:确认
登录并重定向(资源名称,@confirmable)
结束
结束

我想你可能把错误信息和闪光信息混在一起了。当通过
显示错误时,这些错误消息来自在模型上设置的验证。例如,在
用户
模型中

validates :password, presence: true
与flash消息相比,这些错误是不同的。您可以像这样在控制器中设置
flash
消息

def create
  # code .....
  if @post.save
    flash[:success] = "Post was successfully created"
    redirect_to [@investigation, @post]
  else
    flash.now[:error] = "Post was not created"
    render 'new'
  end
end
这些闪存消息只响应您在控制器操作中指定的条件。希望这有帮助