當我試圖做這個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