当我尝试在部分或“显示”视图中执行此 form_for 时,我不断收到此错误。谁能解释我做错了什么?
显示 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 都没有运气......