2010-01-30 70 views
0

好吧,這是我在rails中的第一個應用程序,所以希望這是一個簡單的問題。Rails表單助手失敗

這是我的目標:

- !ruby/object:ProductImage 
attributes: 
image_id: 
product_id: 
created_at: 
updated_at: 
attributes_cache: {} 

這工作:

<%= image_form.text_field :product_id %> 

但我得到了一個未定義的方法`image_id」爲:

<%= image_form.text_field :image_id %> 

我只是不明白這一點...

Cheers for對此有任何幫助。

這是實際的部分:

<div class="image"> 
    <% new_or_existing = product_image.new_record? ? 'new' : 'existing' %> 
    <% prefix = "product[#{new_or_existing}_product_image_attributes][]" %> 
    <% fields_for prefix, product_image do |i| -%> 
    <div class="input select"> 
     <%= i.text_field :image_id %> 
     <%= link_to_function "remove", "$(this).up('.image').remove()" %> 
    </div> 
    <% end -%> 
</div> 

P.S文本字段被用來只是作爲一個例子

+0

好吧,問題出在我的幫助器方法中,我使用的對象來自另一種方法,因爲我複製/粘貼它並沒有仔細檢查 – mynameisrufus 2010-01-30 03:40:16

回答

1

你能後整個窗體?我有一種預感,也許你這樣做:的

<% form_for :image do |image_form| %> 

代替:

<% form_for :product_image do |product_image_form| %> 

當然,我會重新思考顯示形式,其中人手動才能加入的圖像輸入ID值一個產品,但我知道你現在處於學習模式。

0

ID字段不應該是text_fields,它們應該是複選框或下拉選擇框。爲什麼你的使用知道Rails ID是什麼?