2011-04-08 64 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

相關問題