Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ruby variable for class name in HAML

I have the piece of code where I am trying to use a variable for a class name in HAML. Here it is:

      - data_table(@installation_requests, nil, {:placeholder => ''}) do |installation_request, css_class|
          %tr{:class => css_class}

I can't see anything wrong with it, RubyMine IDE doesn't pick an error either, it thinks that it is legitimate use of the variable. I'm getting the following error:

odd number of arguments for Hash

Can anyone point me to what's wrong with the code above?

like image 423
alexs333 Avatar asked Sep 01 '11 03:09

alexs333


1 Answers

What if you try:

- data_table(@installation_requests, nil, {:placeholder => ''}) do |installation_request, css_class|
  %tr{:class => "#{css_class}"}

or if you are saving your views as view.html.haml:

- data_table(@installation_requests, nil, {:placeholder => ''}) do |installation_request, css_class|
  <tr class="#{css_class}">
  ....stuff....
  </tr>
like image 139
Chris Barretto Avatar answered Oct 05 '22 23:10

Chris Barretto