1

i'm trying to use growlflash and set up everything according to the docs. https://github.com/estum/growlyflash

I have this line inside of a rendered partial.html.haml

#header_message = growlyflash_static_notices

And that partial is loaded from my application.html.haml

= render 'shared/app_responsive_header'

But when when the partial is loaded, I get this error

undefined local variable or method `growlyflash_static_notices' for #<#<Class:0x007fe7fb09bd80>:0x007fe7fe889df0>

Am I rendering the partial wrong? Why can't I get this to work.

TuxedoTomson
  • 483
  • 4
  • 16

2 Answers2

1

Try:

= render partial: 'shared/app_responsive_header', locals: {growlyflash_static_notices: growlyflash_static_notices}

Update:

Just looked at the link for its github repo and this won't solve the issue for you. If you look at its docs, it says:

For non-XHR requests append the following before other javascripts inside :

<%= growlyflash_static_notices %>

And require glowlyflash in app/assets/javascripts/application.js

//= require growlyflash/growlyflash

and looking at your code you are probably calling it in body tag which is wrong according to docs. You need to have something like this in your application.html.slim

head
  // other code
  = growlyflash_static_notices
  = stylesheet_link_tag    "application", :media => "all" %>
  = javascript_include_tag "application" %>
  = csrf_meta_tags %>

and in application.js add this line

 //= require growlyflash/growlyflash
Mandeep
  • 9,093
  • 2
  • 26
  • 36
  • Thanks for the quick reply. I'm still having trouble with this. If I add `= growlyflash_static_notices` to my layouts/app_responsive.html.haml file i'm still getting the same error. `layouts/app_responsive.html.haml` is getting loaded instead of my application.html.haml. – TuxedoTomson Sep 12 '14 at 17:41
  • @user3646167 i havent used it so don't know much about it. I just read the docs and pointed it out. Did you try the first approach? Did that work for you? – Mandeep Sep 12 '14 at 17:44
  • @user3646167 did you bundle install it after adding it in gem file and did you require it in application.js? – Mandeep Sep 12 '14 at 17:48
  • First fix didn't work, and everything is bundled and required in application.js – TuxedoTomson Sep 12 '14 at 17:54
  • @user3646167 just tested this in my app and and second method is working for me – Mandeep Sep 12 '14 at 18:07
  • Are you adding = growlyflash_static_notices to your application.html.haml? I'm trying to use it in /layouts/app_responsive.html.haml. Would that make a difference? – TuxedoTomson Sep 12 '14 at 18:23
  • @user3646167 Depends on where you want those flash messages to appear. If you want them to appear in all of your pages then you need to add it in all of your layouts – Mandeep Sep 12 '14 at 18:25
1

Partials do not have access to local variables from the other templates, though they do have access to instance variables. Use the locals option to set any local variables in the partial when you render it:

= render partial: 'shared/app_responsive_header', locals: {growlyflash_static_notices: growlyflash_static_notices}
infused
  • 24,000
  • 13
  • 68
  • 78
  • actually this won't solve the issue, check [`github link for glowlyflash`](https://github.com/estum/growlyflash) – Mandeep Sep 12 '14 at 16:47