繁体   English   中英

Rails:simple_form问题

[英]Rails: Issue with simple_form

我在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'} %>

我认为最好找到一种在视图中排序列表的方法。 但是我很好奇
正在进行...

首先,您不应该覆盖此类方法。

这是使用simple_form的方法

f.association : pessoa, :collection => Pessoa.order(:nome).all

https://github.com/plataformatec/simple_form/#associations

您可以按照此处所述使用default_scope。

在模型中使用此宏可以为模型上的所有操作设置默认范围。

在您的情况下default_scope order(:nome)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM