我在我的rails应用程序中构建了一个simple_form表单,事情进展顺利:
<%= simple_form_for([@folha, @servico], html: {class: 'well form-horizontal'}) do |f| %>
<%= f.association :pessoa, label: 'Funcionário' %>
<%= f.input :funcao, label: 'Função',collection: @funcoes %>
<%= f.input :modulos, label: 'Módulos', input_html: {class: 'span4'} %>
<%= f.input :valor, label: 'Valor por hora', as: :string ,input_html: {class: 'span1'} %>
<%= f.input :horas, as: :string, input_html: {class: 'span1'} %>
<%= f.button :submit, 'Incluir', class: 'btn btn-primary' %>
<% end %>
要更改f.association的下拉列表中的订单列表,我已覆盖Pessoa.rb中的默认.all方法:
def self.all
order :nome
end
然后我在尝试渲染视图时出现此错误:
wrong number of arguments (1 for 0)
Extracted source (around line #5):
2: <h1>Preencher Pagamentos - Folha <%= "#{@folha.mes}/#{@folha.ano}" %> <small> <%= @folha.obs %> </small> </h1>
3: </div>
4: <%= simple_form_for([@folha, @servico], html: {class: 'well form-horizontal'}) do |f| %>
5: <%= f.association :pessoa, label: 'Funcionário' %>
6: <%= f.input :funcao, label: 'Função',collection: @funcoes %>
7: <%= f.input :modulos, label: 'Módulos', input_html: {class: 'span4'} %>
我认为最好找一种在视图中订购列表的方法。但我对什么是非常好奇 正在进行......
答案 0 :(得分:0)
您不应该首先覆盖这些方法。
以下是使用simple_form
的方法f.association : pessoa, :collection => Pessoa.order(:nome).all
答案 1 :(得分:0)