当我试图做这个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 ...
请问您可以显示“show.html.erb”的完整来源吗?根据错误,它看起来像缺少一个'end'关键字。 – 2011-04-08 02:50:23