0

I'm trying to do this tutorial out of the Rails Bible, I created a new contact form and I entered everything from the book:

    <h1>Create New Contact</h1>
<% form_for :contact, :url => { action => 'create' } do |f|
  <p><label for="contact_first_name">First Name:</label>
  <%= f.text_field 'contact', 'first_name' %></p>

  <p><label for="contact_last_name">Last Name:</label>
  <%= f.text_field 'contact', 'last_name' %></p>

  <p><label for="contact_address">Address:</label>
  <%= f.text_field 'contact', 'address' %></p>

  <p><label for="contact_city">City:</label>
  <%= f.text_field 'contact', 'City' %></p>

  <p><label for="contact_state">State:</label>
  <%= f.text_field 'contact', 'state' %></p>

  <p><label for="contact_country">Country:</label>
  <%= f.text_field 'contact', 'country' %></p>

  <p><label for="contact_phone">Phone:</label>
  <%= f.text_field 'contact', 'phone' %></p>

  <p><label for="contact_email">Email:</label>
  <%= f.text_field 'contact', 'email' %></p>

  <%= f.submit "Create" %>
<% end %>  

<p><%= link_to 'Back', { :action => 'index' } %>

And below is my controller file

    class ContactController < ApplicationController

  def index
    @contacts = Contact.find(:all)
  end

  def show
  end

  def new
    @contact = Contact.new
  end
  def create
  end

  def update
  end
end

But I get a syntax error:

SyntaxError in Contact#new

Showing C:/rails_projects/contactlist/app/views/contact/new.html.erb where line #3 raised:

C:/rails_projects/contactlist/app/views/contact/new.html.erb:3: syntax error, unexpected '<'
  <p><label for="contact_first_name">First Name:</label>
   ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:3: syntax error, unexpected tLABEL, expecting keyword_do or '{' or '('
  <p><label for="contact_first_name">First Name:</label>
                                                ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:4: unknown regexp option - p
end pattern with unmatched parenthesis: /label>
  <%= f.text_field 'contact', 'first_name' ;@output_buffer.safe_concat('</
C:/rails_projects/contactlist/app/views/contact/new.html.erb:6: syntax error, unexpected '<'
  <p><label for="contact_last_name">Last Name:</label>
   ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:6: syntax error, unexpected tLABEL, expecting keyword_do or '{' or '('
  <p><label for="contact_last_name">Last Name:</label>
                                              ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:7: unknown regexp option - p
unmatched close parenthesis: /label>
  ');@output_buffer.append= ( f.text_field 'contact', 'last_name' );@output_buffer.safe_concat('</
C:/rails_projects/contactlist/app/views/contact/new.html.erb:9: syntax error, unexpected '<'
  <p><label for="contact_address">Address:</label>
   ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:9: syntax error, unexpected tLABEL
  <p><label for="contact_address">Address:</label>
                                          ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:10: unknown regexp option - p
unmatched close parenthesis: /label>
  ');@output_buffer.append= ( f.text_field 'contact', 'address' );@output_buffer.safe_concat('</
C:/rails_projects/contactlist/app/views/contact/new.html.erb:12: syntax error, unexpected '<'
  <p><label for="contact_city">City:</label>
   ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:12: syntax error, unexpected tLABEL
  <p><label for="contact_city">City:</label>
                                    ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:13: unknown regexp option - p
unmatched close parenthesis: /label>
  ');@output_buffer.append= ( f.text_field 'contact', 'City' );@output_buffer.safe_concat('</
C:/rails_projects/contactlist/app/views/contact/new.html.erb:15: syntax error, unexpected '<'
  <p><label for="contact_state">State:</label>
   ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:15: syntax error, unexpected tLABEL
  <p><label for="contact_state">State:</label>
                                      ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:16: unknown regexp option - p
unmatched close parenthesis: /label>
  ');@output_buffer.append= ( f.text_field 'contact', 'state' );@output_buffer.safe_concat('</
C:/rails_projects/contactlist/app/views/contact/new.html.erb:18: syntax error, unexpected '<'
  <p><label for="contact_country">Country:</label>
   ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:18: syntax error, unexpected tLABEL
  <p><label for="contact_country">Country:</label>
                                          ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:19: unknown regexp option - p
unmatched close parenthesis: /label>
  ');@output_buffer.append= ( f.text_field 'contact', 'country' );@output_buffer.safe_concat('</
C:/rails_projects/contactlist/app/views/contact/new.html.erb:21: syntax error, unexpected '<'
  <p><label for="contact_phone">Phone:</label>
   ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:21: syntax error, unexpected tLABEL
  <p><label for="contact_phone">Phone:</label>
                                      ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:22: unknown regexp option - p
unmatched close parenthesis: /label>
  ');@output_buffer.append= ( f.text_field 'contact', 'phone' );@output_buffer.safe_concat('</
C:/rails_projects/contactlist/app/views/contact/new.html.erb:24: syntax error, unexpected '<'
  <p><label for="contact_email">Email:</label>
   ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:24: syntax error, unexpected tLABEL
  <p><label for="contact_email">Email:</label>
                                      ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:25: unknown regexp option - p
unmatched close parenthesis: /label>
  ');@output_buffer.append= ( f.text_field 'contact', 'email' );@output_buffer.safe_concat('</
C:/rails_projects/contactlist/app/views/contact/new.html.erb:30: syntax error, unexpected '<', expecting keyword_end
<p>');@output_buffer.append= (...
 ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:30: syntax error, unexpected tCONSTANT, expecting keyword_end
..._buffer.append= ( link_to 'Back', { :action => 'index' } );@...
...                               ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:30: syntax error, unexpected tIDENTIFIER, expecting keyword_end
..._to 'Back', { :action => 'index' } );@output_buffer.to_s
...                               ^
C:/rails_projects/contactlist/app/views/contact/new.html.erb:30: unterminated string meets end of file
C:/rails_projects/contactlist/app/views/contact/new.html.erb:30: syntax error, unexpected $end, expecting keyword_end
Extracted source (around line #3):

1: <h1>Create New Contact</h1>
2: <% form_for :contact, :url => { action => 'create' } do |f|
3:   <p><label for="contact_first_name">First Name:</label>
4:   <%= f.text_field 'contact', 'first_name' %></p>
5:   
6:   <p><label for="contact_last_name">Last Name:</label>
Trace of template inclusion: app/views/contact/new.html.erb

Rails.root: C:/rails_projects/contactlist

Application Trace | Framework Trace | Full Trace
Request

Parameters:

None
Show session dump

Show env dump

Response

Headers:

None

I even used a validator to make sure the HTML was correct. I created the form to correlate with a new action I put in the controller. How can I fix this error?

0

3 Answers 3

2

You are missing a closing rails tag

you have

<% form_for :contact, :url => { action => 'create' } do |f|

You are missing the %> and the action symbol's :

<% form_for :contact, :url => { :action => 'create' } do |f| %>

EDIT: You can see this in your sytax error. If you can't find anything wrong with the specific line quoted in the error your first thought should be to look at the line above it.

Sign up to request clarification or add additional context in comments.

1 Comment

That helped thanks! Now I'm getiing a new error "saying that i have an undefined method on line 4", I'm trying to figure it out.
0

You're just missing a %>

Change the first line to the following:

<% form_for :contact, :url => { action => 'create' } do |f| %>

Comments

0

try this out:-

<%= form_for :contact, :url => { action => 'create' } do |f| %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.