0

Why im feeling that someone is under my mousepoint_jumps? that is the error: SyntaxError in Posts#new when i load the page and:

C:/Sites/blog/app/views/posts/_form.html.erb:2: syntax error, unexpected ')', expecting keyword_then or ';' or '\n'
...ppend= ( if @post.errors.any? );@output_buffer.safe_concat('
...                               ^
C:/Sites/blog/app/views/posts/_form.html.erb:12: syntax error, unexpected keyword_end, expecting ')'
');  end 
        ^
C:/Sites/blog/app/views/posts/_form.html.erb:26: syntax error, unexpected keyword_end, expecting ')'
'); end ;@output_buffer.to_s
       ^
C:/Sites/blog/app/views/posts/_form.html.erb:27: syntax error, unexpected keyword_ensure, expecting ')'
C:/Sites/blog/app/views/posts/_form.html.erb:29: syntax error, unexpected keyword_end, expecting ')'

Extracted source (around line #2):

1: <%= form_for @post do |f| %>
2:  <%= if @post.errors.any? %>
3:  <div id="errorExplanation">
4:      <h2><%= pluralize(@post.errors.count, "error") %> prohibited
5:          this post from beign saved:</h2>

and this is the file:

<%= form_for @post do |f| %>
    <%= if @post.errors.any? %>
    <div id="errorExplanation">
        <h2><%= pluralize(@post.errors.count, "error") %> prohibited
            this post from beign saved:</h2>
        <ul>
        <%= @post.errors.full_messages.each do |msg| %>
            <li><%= msg %></li>
        <% end %>
        </ul>
    </div>
    <% end %>
    <p>
        <%= f.label :title %><br>
        <%= f.text_field :title %>
    </p>

    <p>
        <%= f.label :text %><br>
        <%= f.text_area :text %>
    </p>

    <p>
        <%= f.submit %>
    </p>
<% end %>

im working in that ruby tutorial hard and deeply, but something is behind the nice errors. I love the errors, is true. But this is too much! Can i get any evidence of my wrong work here.

Baldrick
  • 23,882
  • 6
  • 74
  • 79
Hell0
  • 349
  • 1
  • 6
  • 19

1 Answers1

2

It should be the follwing (notice <%= has been replace by <%)

<% if @post.errors.any? %>

Same thing for

<% @post.errors.full_messages.each do |msg| %>

See this question on ERB syntax for more details. Basically <%= is used to insert dynamic content in the page; <% is for control statements (conditions, loops, etc...).

Community
  • 1
  • 1
Baldrick
  • 23,882
  • 6
  • 74
  • 79