开发者

How can I prevent the printing of the return value of a closure in Rails?

开发者 https://www.devze.com 2023-01-15 10:51 出处:网络
In a given html.erb file, I have <%= render \"steps_list\", :post => @post%> In开发者_运维技巧 _steps_list.html.erb, I have

In a given html.erb file, I have

<%= render "steps_list", :post => @post%>

In开发者_运维技巧 _steps_list.html.erb, I have

<%= @post.step_names.each do |step| %>
    Step: <%= "#{step}" %>
<% end %>

This works well with one exception. Each step is printed out as I want, but the entire array is also printed out at the end.

Step: Rinse Step: Lather Step: Repeat RinseLatherRepeat

I suspect the entire array is printed out at the end because the closure returns the array when it's finished executing. How do I suppress the printing of the array or the return value of the closure?


Use this instead.

<% @post.step_names.each do |step| %>
    Step: <%= "#{step}" %>
<% end %>

<%= ### %> means "print the output of this".

0

精彩评论

暂无评论...
验证码 换一张
取 消