2015-12-14 156 views
1

我該如何獲得此工作?Rails:提交更改表格

<%= form_for current_user, html: {multipart: true } do |f| %> 
    <%= f.select(:brand, Brand.pluck(:company), {prompt:true}, {class: 'form-control'}, {:onchange => 'this.form.submit()'}) %> 
<% end %> 

目標是自動提交變更表單。但上面的代碼不起作用。我收到一個wrong number of arguments (5 for 1..4)錯誤。有任何想法嗎?

回答

1

最後三個參數其實有一個hash選項。試着將它們放在括號中作出明確表示,他們沒有更多的參數:

<%= f.select(:brand, Brand.pluck(:company), (prompt: true, class: 'form-control', :onchange => 'this.form.submit()')) %> 

或alertatively

<%= f.select(:brand, Brand.pluck(:company), options {prompt:true, class: 'form-control', :onchange => 'this.form.submit()'}) %> 
0

明白了。刪除{prompt:true},它的工作原理!

0

選擇助手:

select(object, method, choices = nil, options = {}, html_options = {}, &block) 

這應該與提示也行:

<%= f.select(:brand, Brand.pluck(:company), {include_blank: true, class: 'form-control'}, :onchange => 'this.form.submit()') %> 

Rails select helper