设计:注册控制器不显示Flash消息

时间:2014-01-28 13:25:58

标签: ruby-on-rails ruby flash devise flash-message

我创建了注册控制器,用Devise覆盖默认值。一切都运行良好,但闪存消息 - 当用户进行新的注册时,我想在他的主页上重定向他,并向他显示有关正在发生的事情的快速消息,如下所示:

class RegistrationsController < Devise::RegistrationsController
  def new
    super
  end

  def create
    resource = build_resource(params[:user])
    # add custom create logic here
    if params[:referrer_key].nil?
      puts 'A'
      puts resource.inspect
      if resource.save
        puts 'B'
        if resource.active_for_authentication?
          #flash[:notice] = "Welcome!" # doesn't work neither
          Notification.welcome(@user).deliver unless @user.invalid? # overriding original methods       
          sign_in(@user)
          redirect_to root_url, :notice => "Welcome!"
        else
          set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
          expire_session_data_after_sign_in!
          respond_with resource, :location => after_inactive_sign_up_path_for(resource)
        end
      else
        clean_up_passwords resource
        render 'application/splash'
      end

用户已注册,已登录,也会发送通知电子邮件,但不显示Flash消息。

我如何显示Flash消息:

#flash-display
        - flash.each do |type, msg|
          %div{:class => "alert alert-#{type == :notice ? "success" : type} fadeout", "data-dismiss" => "alert"}
            %button.close &times;
            = msg if msg.is_a?(String)

Flash消息通常有效,但不适用于此情况。

我可能错过了什么?

谢谢

1 个答案:

答案 0 :(得分:0)

你必须使用不同的引号,否则div类搞砸了:

%div{:class => "alert alert-#{type == :notice ? 'success' : type} fadeout", "data-dismiss" => "alert"}
相关问题