2015-12-14 160 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