I am trying to teach myself Ruby and Ruby on Rails. Can someone give me some quick pointers on this code from http://guides.rubyonrails.org/getting_started.html
<%= form_for(@post) do |f| %>
<% if @post.errors.any? %>
<div id="errorExplanation">
<h2><%= pluralize(@post.errors.count, "error") %> prohibited
this post from being saved:</h2>
<ul>
<% @post.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :content %><br />
<%= f.text_area :content %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Questions:
- Sometimes the code uses
<%
and sometimes uses<%=
. When do I use either of these? - What exactly does
@
mean in Ruby and when is is used? - Besides for the HTML, is all of Ruby code, or there some new code/syntax which Ruby on Rails introduces?