Ruby on Rails Thursday, April 28, 2016

On 28 April 2016 at 16:28, gvim <gvimrc@gmail.com> wrote:
> "Agile Web Development with Rails 5", p.76 lists a form partial which
> begins:
>
> <%= form_for(product) do |f| %>
> <% if product.errors.any? %>
> <div id="error_explanation">
> <h2><%= pluralize(product.errors.count, "error") %> prohibited this
> product from being saved:</h2>
>
> <ul>
> <% product.errors.full_messages.each do |message| %>
> <li><%= message %></li>
>
> It is correct but I'm confused about the first line as I understood that
> control structures begin with <% as in the 2nd line and that <%= is reserved
> for inserting values and calling formatting functions.

That is almost correct. Lines with <% are evaluated but nothing is
inserted into the page. Lines with <%= are evaluated and the returned
value (string) is inserted into the page. Since form_for has to
insert the form tag into the page then it has to be <%=

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLsvCAGN%3Dh%3DtELV9R%3DmYMhne_5T%3D_Yjatm%3Dw7v7hfQ8VuA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment