Search code examples
rubyruby-on-rails-4sasshamlflash-message

Flash messages in Rails f not showing up any more


I should mention that they were showing up a few commits ago. Since they stopped working, I know that I've added Stripe for payments, and efax to send faxes. I disregarded the issue for a few commits as I focused on other things thinking it would be a quick fix, however I haven't been able to figure it out.

I don't think its the format in which I'm calling the flash messages - to give an idea, here's one of my create actions in one of my controllers:

  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

end

I've tried changing the format, and flipping around the "notice:" and "redirect_to" without success, however this is the original format that was working at one point.

Here is my application layout, in haml format (indents are identical to my code, in case that's the issue somewhere)

%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

And finally, here's the relevant CSS code, p.notice (its a css.sass file):

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

From my somewhat limited understanding of Rails, I don't think there's anything else that impacts flash messages - unless there's possibly a config I turned off somewhere and didn't realize?

I can post more code if needed, but right now I have no idea where else to look.

Thanks guys!


Solution

  • pay attention to = :notice and = alert

    expected flash[:notice] and flash[:alert]