0

部分ビューまたは「表示」ビューのいずれかでこのform_forを実行しようとすると、このエラーが発生し続けます。誰かが私が間違っていることを説明できますか?

行#1が発生したc:/.../show.html.erbを表示しています:

c:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:272: syntax error, unexpected ')'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:273: syntax error, unexpected '?', expecting $end
Extracted source (around line #1):

1: <%= form_for(@post) do |f| %>
2:   <div class="field">
3:     <%= f.text_area :content %>
4:   </div>

この時点で、私のコントローラーには次のものしかありません。

def show  
     @post = Post.new  
end  

そして、私の見解は次のとおりです。

<%= form_for(@post) do |f| %>  
  <div class="field">  
    <%= f.text_area :content %>  
 </div>  
 <div class="actions">  
    <%= f.submit "Submit" %>  
  </div>  
<% end %>  

私のモデルは:

# == Schema Information  
#  
# Table name: posts  
#   
#  id         :integer         not null, primary key  
#  content    :string(255)  
#  approved?  :boolean  
#  kid_id     :integer  
#  created_at :datetime  
#  updated_at :datetime  
#  
class Post < ActiveRecord::Base  
  belongs_to :kid  
  attr_accessible :content  
  validates :content, :presence => true, :length => { :maximum => 140 }  
  validates :kid_id, :presence => true  



default_scope :order => 'posts.created_at DESC'

end

Rails3の2つの異なるバージョンを試してみましたが運がありませんでした...

4

1 に答える 1

0

確実に判断するのは難しいですが、ビューから提供したコードとエラーメッセージに基づいて、form_forをendで閉じるのを忘れた可能性があります。

<%= form_for(@post) do |f| %>
   <%= f.text_area :content %>
<% end %>

編集:

モデルを見ると、データベースの列の1つに質問マークを追加することで、実際に問題を再現することができました。

テーブルの列には、疑問符などの特殊文字を含めないでください。承認された列の名前を変更しますか?承認され、動作するはずです。

于 2011-04-08T02:51:10.440 に答える