What is the difference between <%= … %> and <% … %> in Ruby on Rails

前端 未结 3 1829
难免孤独
难免孤独 2020-12-06 21:18

Does it have something to do with output?

So, <%= ...code... %> is used for outputting after code is executed, and <% ...code... %>

3条回答
  •  生来不讨喜
    2020-12-06 22:01

    <%= is used to output the value of a single expression, e.g.

    <%= object.attribute %>
    <%= link_to 'Link Title', link_path %>
    

    while <% is used to execute arbitrary Ruby code.

提交回复
热议问题