Using ruby โ€‹โ€‹variable for class name in HAML

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

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

I donโ€™t see anything wrong with that, the RubyMine IDE will not choose an error either, it considers this to be a legitimate use of a variable. I get the following error:

odd number of arguments for Hash

Can someone tell me what is wrong with the code above?

+5
source share
2 answers

What if you try:

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

or if you save your views as view.html.haml:

- data_table(@installation_requests, nil, {:placeholder => ''}) do |installation_request, css_class|
  <tr class="#{css_class}">
  ....stuff....
  </tr>
+6
source

A hash can actually accurately pass the array passed to it into a sequence of keys and values.

For instance,

Hash["a", "apple", "b", "boy"]       #=> {"a"=>"apple", "b"=>"boy"}

, splat /...

Hash["a", "apple", "b", "boy", "c"]  #=> odd number of arguments for Hash

, , - data_table. , , , Hash - !

0

All Articles