Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8817769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:55:55+00:00 2026-06-14T04:55:55+00:00

I try to convert the code from haml to erb but I’m getting stuck

  • 0

I try to convert the code from haml to erb but I’m getting stuck and don’t know why.

Here is the original code I want to convert: https://github.com/gmarik/simple-backend-example/blob/master/app/views/backend/resource/_index.html.haml

And here is what I have right now. Can someone take a look at it and give me some hints. Thanks.

I doubt this line the most:
%tr[resource]{odd_or_even}

I think that it might be like:
<tr> <% @resource{odd_or_even} %>

RubyMine gave me an error at this line:
<%= paginate collection %>

    <% content_for(:header) do %>
      <h1><%= resource_class.model_name.human(count: 2) %></h1>

    <ul class="tabs">
       <li class="active"><%= link_to "Index", "#" %></li>
       <li><%= link_to "New", new_resource_path %> </li>
    </ul>
    <table class='zebra-striped'>
      <thead>
        <tr>
          <% attributes.each do |attr| %>
            <th> <%= resource_class.human_attribute_name(attr) %></th>
          <th> &nbsp;</th>
        </tr>
      </thead>
      <tbody>
        <% collection.each do |resource| %>
          <tr> <% @resource{odd_or_even} %>
            <% attributes.each do |attr| %>

            <td> <%= resource.public_send(attr).to_s.truncate(20) %> </td>        
            <td class='row-actions'>
              <%= link_to 'show', resource_path(resource) %>
              |
              <%= link_to 'edit', edit_resource_path(resource) %>
              |
              <%= link_to 'destroy', resource_path(resource), method: :delete, confirm: "Are you sure?" %>
            </td>
        <% end %> 
      </tbody> 
    </table>  
    <%= paginate collection %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:55:56+00:00Added an answer on June 14, 2026 at 4:55 am

    Looking at the documentation here : http://haml.info/docs/yardoc/file.REFERENCE.html#object_reference_

    I’d say it’s :

    <tr id="<%= "#{resource.class.name.underscore}_#{resource.to_key}" %>" class="<%= resource.class.name.underscore %>">
    

    This is to translate %tr[resource].

    Now, the {odd_or_even} will just convert the result hash of the helper odd_or_even to map them as attributes on the tr.

    If we take a look at the definition of the method here : https://github.com/gmarik/simple-backend-example/blob/master/app/helpers/backend/application_helper.rb

    We see it’s just a call to cycle in order to set an extra class. Therefore we end up with:

    <tr id="<%= "#{resource.class.name.underscore}_#{resource.to_key}" %>" class="<%= "#{resource.class.name.underscore} #{cycle("odd", "even", name: "rows")}" %>">
    

    Now, all of this won’t fix the problem of paginate. Add the error message if you’re still stuck on this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to convert an anonymous type to class but I don't. My code
I try to convert a part of code from VBScript to C#. I have
We try to convert from string to Byte[] using the following Java code: String
In Java you can try to convert any String value to Integer, but when
Possible Duplicate: Convert some code from C++ to C I've got some code that
I can convert html files to pdfs with iTextSharp using code from Kyle in
I try to convert an svg into PNG. the svg document is coming from
I am trying to convert some code from using DOM (via jDOM) to use
Am trying to convert my string value(the value is millisecond value) from seconds. Here
Need to convert the following code from Ruby to C#. However I'm kind of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.