Rails - Why is HAML showing the full hash?
- by Mr. Demetrius Michael
View:
!!!
%html
%head
%title= full_title(yield(:title))
=stylesheet_link_tag "application", media: "all"
=javascript_include_tag "application"
=csrf_meta_tags
=render 'layouts/shim'
%body
=render 'layouts/header'
.container
=flash.each do |key, value|
%div{class: "alert alert-#{key}"} #{value}
Controller
def create
@user = User.new(params[:user])
if @user.save
flash[:success] = "This is Correct"
redirect_to @user
else
flash[:wrong] = "no"
render 'new'
end
end
Regardless of the flash (:success or :wrong or otherwise) it always compiles the entire hash as html (below)
Output:
<!DOCTYPE html>
....
<div class='container'>
<div class='alert alert-wrong'>no</div>
{:wrong=>"no"}
</div>
</body>
</html>
I have no idea why {:wrong=>"no"} is being displayed. I've been staring at this terminal for hours. What's interesting is that the hash is being outputted with the container id, but not in the alert class. It feels like an indentation problem, but I went through several permutations with no success.