2011-04-08 103 views
0

当我试图做这个form_for,无论是在部分或在“显示”视图中,我不断收到此错误。任何人都可以解释我做错了什么?为什么在使用form_for时会出现attribute_methods错误?

显示C:/.../ show.html.erb其中线#1提出:

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 

即使尝试了两种不同的版本,没有运气的Rails 3 ...

+0

请问您可以显示“show.html.erb”的完整来源吗?根据错误,它看起来像缺少一个'end'关键字。 – 2011-04-08 02:50:23

回答

0

这很难说肯定,但根据你的观点和错误信息提供的代码,你可能忘了关用的form_for结束:

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

编辑:

看着你的模型其实我设法通过增加一个问号到我的数据库列的一个重现您的问题。

表中的列不应包含任何特殊字符,如questionmark。重命名批准的列?批准,它应该工作。

+0

我现在正在显示整个代码。我在那里结束了。不过,希望是这样!感谢您的关注。 (这让我疯狂!) – icewoman27 2011-04-08 03:22:52

+0

Okey,你的表单看起来不错,所以我认为问题在于你的Post模型。你是否也可以提供该模型的代码,并包含属性的名称,以防它们是保留字或什么的? – DanneManne 2011-04-08 03:31:06

+0

现在添加模型。再次感谢! – icewoman27 2011-04-08 03:55:55

相关问题