2012-07-28 34 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