2012-07-28 39 views
0

我已经建立了一个simple_form形式在我的Rails应用程序和事情进展得很好: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:

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

def self.all 
    order :nome 
end 

然后我试图使我的看法时,得到这个错误我认为最好找到一种方法来在视图中排列列表。但即时通讯非常好奇
正在进行...

+0

如果您想覆盖'all'方法,您应该执行'super.order:nome'。但是使用'default_scope - > {order:nome}' – 2014-01-10 13:50:39

回答

0

您可以使用default_scope描述here

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

在你的情况default_scope order(:nome)

+0

会更好 - 我刚刚看到它:Mirko Akkov已经在评论中描述了这一点。 – phikes 2014-07-08 10:31:59