2012-07-28 3 views
0

simple_form에 문제는 잘 갔다 :레일 : 나는 내 레일 애플 리케이션과 사물에 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 기본 :

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}'를 사용하는 것이 더 낫습니다. –

답변

0

그것을 수행하는 방법이다.

모델에서이 매크로를 사용하여 모델의 모든 작업에 대한 기본 범위를 설정합니다.

귀하의 경우에는 default_scope order(:nome)입니다.

+0

방금 ​​본 것 : Mirko Akkov는 이미 주석에서 이것을 설명했습니다. – phikes

관련 문제