0

Rails Bible からこのチュートリアルを実行しようとしています。新しいお問い合わせフォームを作成し、本からすべてを入力しました。

    <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' } %>

以下は私のコントローラーファイルです

    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

しかし、構文エラーが発生します。

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

HTML が正しいことを確認するためにバリデーターも使用しました。コントローラーに追加した新しいアクションに関連付けるフォームを作成しました。このエラーを修正するにはどうすればよいですか?

4

3 に答える 3

2

Rails の終了タグがありません

あなたが持っている

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

%>およびアクション シンボルがありません:

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

編集:これは構文エラーで確認できます。エラーで引用されている特定の行に問題が見つからない場合は、まずその上の行を確認する必要があります。

于 2013-06-13T17:35:53.793 に答える
0

これを試してください:-

<%= form_for :contact, :url => { action => 'create' } do |f| %>
于 2013-06-13T17:58:39.867 に答える
0

あなたはちょうど行方不明です%>

最初の行を次のように変更します。

<% form_for :contact, :url => { action => 'create' } do |f| %>
于 2013-06-13T17:44:51.723 に答える