One*_*ero 2 ruby ruby-on-rails
有什么区别
<% some code %>
Run Code Online (Sandbox Code Playgroud)
和
<%= some code %>
Run Code Online (Sandbox Code Playgroud)
在RoR?
Kev*_*ell 10
可以这样想:
<% execute this code and display nothing %>
Run Code Online (Sandbox Code Playgroud)
和
<%= execute this code and display the result in the view %>
Run Code Online (Sandbox Code Playgroud)
所以,例如你可以这样做:
<% @values = ['eenie', 'menie', 'miney', 'mo' ] %>
<% @values.each do |value| %>
The current value is <%= value %>!
<% end %>
Run Code Online (Sandbox Code Playgroud)