2013-07-24 95 views
0

我試圖創建選擇,這將只是不能直接發佈到這裏的服務器搜索 形式使用與查看代碼:simple_form沒有模型和選擇框

= simple_form_for :tags, url: '#' do |f| 
    = f.input 'id[]', collection: @tags 

@tags是隻有主動關係 - 標籤它來自行爲-AS-加標籤上 這裏是從控制器我的代碼:

@tags = project.user_statuses.tag_counts_on(:tags) 

從控制檯升ooks像:

[#<ActsAsTaggableOn::Tag id: 1, name: "amazing">, 
#<ActsAsTaggableOn::Tag id: 2, name: "bfc-release">, 
#<ActsAsTaggableOn::Tag id: 3, name: "demo">, 
#<ActsAsTaggableOn::Tag id: 4, name: "awesome">, 
#<ActsAsTaggableOn::Tag id: 5, name: "project1">] 

,但我得到 未定義的方法`ID []」爲# 在我看來。我做錯了什麼?

回答

0

SimpleForm試圖獲得該字段的值。它取對象(:tags)併發送一個名爲字段(id[])的方法。所以這導致:tags.send 'id[]'。因爲Symbol類沒有這樣的方法,所以你得到了錯誤。

在對象不是模型的情況下,使用simple_form_for也許是個壞主意。

0

看來,這是一個只是壞的語法和非知識性錯誤信息

它出現時我加上「:選擇框」選項:

= simple_form_for :tag, url: '#' do |f| 
    = f.input 'ids', 
    as: :select, 
    collection: @tags, 
    label_method: :name, 
    value_method: :id, 
    input_html: {:multiple => false} 
相關問題