Skip to content

Instantly share code, notes, and snippets.

@garethrees
Created April 5, 2012 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garethrees/2309215 to your computer and use it in GitHub Desktop.
Save garethrees/2309215 to your computer and use it in GitHub Desktop.
Flash outputs random 0
= if notice
#notice
%p
= notice
%h2.breadcrumb
= link_to 'Sites', admin_sites_path
= render :partial => "shared/noticedisplay"
%h1 Sites (Campuses) #{link_to_icon 'add', new_admin_site_path}
<h2 class="breadcrumb">
<a href="/admin/sites">Sites</a>
</h2>
<div id="notice">
<p> The testy campus was successfully created. </p>
</div>
0
<h1>
Sites (Campuses)
<a class="icon add_icon" href="/admin/sites/new">
<img src="/images/icons/add.png?1333534032" alt="Add">
</a>
</h1>
def create
@site = Site.new(params[:site])
if @site.save
redirect_to(admin_sites_path,:notice => ["The "+@site.name+" campus was successfully created."])
else
redirect_to(admin_sites_path,:error => ["Campus creation failed!"])
end
end
@garethrees
Copy link
Author

I'm thinking it's something in the partial. When I made my flash partial I remember getting an empty <div> unless I used unless flash.blank?. I also pass the flash object to the partial: <%= render "shared/flash", :object => flash %>

Try a couple of those and let me know how it goes.

@barryrichards
Copy link

Just tried those.
Adding = unless flash.blank? to the start of the flash partial actually produces a second zero! :-S Like this:

< div id="notice">
< p> The testing campus was successfully created. < /p>
< /div>
0 0
< h1>
# (Ignore spaces in tags)

Passing the flash object made no difference either, it still displayed a zero.

:-|

@garethrees
Copy link
Author

Wonder if its a haml bug? I don't really use haml, but it could be doing something weird while its converting to html.

Try writing the partial in erb.

@barryrichards
Copy link

I think you're on the money. Switched to erb and it works fine, no random numbers. That'll do for me. Bug fixed.
Cheers for your help Gareth, it's much appreciated.
Thanks
Barry

@garethrees
Copy link
Author

Hah, should have spotted that. Like I said, I don't use haml much :P

Edit: Referencing Keeran's spot

Use - instead of = for conditionals:

- if notice 
  #notice
    %p
      = notice

@barryrichards
Copy link

Yup, that's the error. Not a bug. Blame the coder ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment