kwaigon
kwaigon

Reputation: 815

Embed ruby code inside view with HAML?

For example, I have such line:

<tr class="<%= cycle('list_line_odd', 'list_line_even') %>">

How I can translate it into HAML?

Upvotes: 2

Views: 2309

Answers (1)

Dave Newton
Dave Newton

Reputation: 160170

%tr{ class: cycle('list_line_odd', 'list_line_even') }

Response to comments, which is a separate question:

This is your source, from your pastie:

%tr{:class => cycle('list_line_odd', 'list_line_even')}
  %th
  - @books.each do |book|
    %tr

The above applies cycle to the outer-most table row, not each individual book's row:

%tr
  %th
  - @books.each do |book|
    %tr{ class: cycle('list_line_odd', 'list_line_even') }

Upvotes: 5

Related Questions