【问题标题】:Flash messages in Rails f not showing up any moreRails f 中的 Flash 消息不再显示
【发布时间】:2015-04-02 21:11:41
【问题描述】:

我应该提到他们在几个提交之前就出现了。自从他们停止工作后,我知道我已经添加了 Stripe 用于付款,并添加了 efax 以发送传真。我忽略了一些提交的问题,因为我专注于其他事情,认为这将是一个快速修复,但是我无法弄清楚。

我不认为它是我调用 flash 消息的格式 - 给出一个想法,这是我在我的一个控制器中的一个创建操作:

  def create
     @vendor = @company.vendors.build(vendor_params)    
     respond_to do |format|
  if @vendor.save
    format.html { redirect_to vendors_url, notice: 'Vendor was successfully created.' }
    format.json { render :show, status: :created, location: @vendor }
  else
    format.html { render :new }
    format.json { render json: @vendor.errors, status: :unprocessable_entity }
  end
end

结束

我已尝试更改格式,并在“notice:”和“redirect_to”周围翻转但未成功,但这是在某一时刻有效的原始格式。

这是我的应用程序布局,采用 haml 格式(缩进与我的代码相同,以防出现问题)

%html
%head
    - unless user_signed_in?
        %title Welcome to Swiftorders
    - else
        %title
            ="#{@company.name} ~ Swiftorders"
    = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
    = javascript_include_tag 'https//js.stripe.com/v2/', 'application', 'data-turbolinks-track' => true
    %script{:src => "//use.typekit.net/odj6wem.js"}
    :javascript
        try{Typekit.load();}catch(e){}
    = csrf_meta_tags
    = tag :meta, :name => :secret_key, :content => :publishable_key
- unless user_signed_in?
    %body.splash
    .logo
    = yield
- else
    %body
    .app-wrapper.clear
        - if flash[:notice]
            %p.notice
                = :notice
        - if flash[:alert]
            %p.alert
                = alert
        = render "layouts/sidebar"
        .content
            = render "layouts/header"
            .sheet
                = yield

最后,这是相关的 CSS 代码 p.notice(它是一个 css.sass 文件):

p.notice
    position: absolute
    opacity: 0.7
    margin: 0px
    bottom: 0
    z-index: 99
    width: 100%
    text-align: center
    font-size: 18px
    font-weight: 300
    padding: 20px
    color: #fff
    background: #000

根据我对 Rails 的有限了解,我认为没有其他因素会影响 Flash 消息 - 除非可能存在我在某处关闭但没有意识到的配置?

如果需要,我可以发布更多代码,但现在我不知道该去哪里找。

谢谢大家!

【问题讨论】:

    标签: ruby ruby-on-rails-4 sass haml flash-message


    【解决方案1】:

    关注= :notice= alert

    预计 flash[:notice]flash[:alert]

    【讨论】:

    • 我想通了(我会添加一个解决方案) - 我放了“config.middleware.use ActionDispatch::Cookies”和“config.middleware.use ActionDispatch::Session::CookieStore”在我的 application.rb 文件中修复另一个问题,将这些注释掉修复了我的闪存消息。同样, = :notice 使得闪烁的消息只是“通知”,而不是预期的消息。谢谢维克多!
    【解决方案2】:

    我想通了——我把 “config.middleware.use ActionDispatch::Cookies”和 我的 application.rb 文件中的“config.middleware.use ActionDispatch::Session::CookieStore”修复了另一个问题,将这些注释掉修复了我的 flash 消息。同样, = :notice 使得闪烁的消息只是“通知”,而不是预期的消息。

    【讨论】:

      猜你喜欢
      • 2015-10-22
      • 1970-01-01
      • 1970-01-01
      • 2014-01-28
      • 1970-01-01
      • 2019-11-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多