Why am I getting an attribute_methods error when using form_for?
I keep getting this error when I attempt to do this form_for, either in a partial or in the "show" view. Can anyone explain what I'm doing wrong?
Showing c:/.../show.html.erb where line #1 raised:
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>
At this point, my controller only has this:
def show
@post = Post.new
end
And my view only has:
<%= form_for(@post) do |f| %>
<div class="field">
<%= f.text_area :content %>
</div>
<div class="actions">
&l开发者_开发知识库t;%= f.submit "Submit" %>
</div>
<% end %>
My model is:
# == 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
Even tried two different versions of Rails 3 with no luck...
It's hard to tell for sure but based on the code you supplied from the view and the error message, you probably forgot to close the form_for with end:
<%= form_for(@post) do |f| %>
<%= f.text_area :content %>
<% end %>
Edit:
Looking at your model I actually managed to reproduce your problem by adding a questionmark to one of my database columns.
The columns in your tables should not contain any special characters like questionmark. Rename the column approved? to approved and it should work.
精彩评论