Ruby on Rails

Quality Sources



Why does it matter when I include parens around a method call inside an Erb template?

This works:

      <td><%= image_tag product.image_url, :class => 'list_image' %></td>

This fails:
ActionView::Template::Error (/Users/john/development/learn/ror/work/depot/app/views/products/index.html.erb:17: syntax error, unexpected ',', expecting ')'
...( image_tag (product.image_url, :class => 'list_image') );@o...
...                               ^
/Users/john/development/learn/ror/work/depot/app/views/products/index.html.erb:17: syntax error, unexpected ')', expecting keyword_end
..._url, :class => 'list_image') );@output_buffer.safe_concat('...
...                               ^):
    15:   <% @products.each do |product| %>
    16:     <tr class="<%= cycle('list_line_odd', 'list_list_even') %>">
    17:       <td><%= image_tag (product.image_url, :class => 'list_image') %></td>
    18:       <td class="list_description">
    19:         <dl>
    20:           <dt><%= product.title %></dt>
  app/controllers/products_controller.rb:7:in `index'

Raw Notes

  • Instance variables in Controllers are exported in their corresponding views.
  • Pluralization tool:
  • OOTB, rails provides three kinds of view templating:
    1. Erb
    2. XML builder
    3. RJS — Ruby JavaScript (for generating javascript to run on the browser)


Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License