레일 3.2.12 및 루비 1.9.3 및 Haml중첩 된 양식의 특성을 계산합니까?
나는 'link_to "remove"'의 디스플레이를 제어하기 위해 속성의 수를 사용하고 싶지만 논리 설정에 문제가 있습니다.
이.field
= codeline.label :name, "Units Alloc"
%br/
= codeline.text_field :units_alloc, :precision => 6, :scale => 2, :size => 10,
:class => "ui-state-default"
= codeline.hidden_field :_destroy
= link_to "remove", '#', class: "remove_fields"
이 잘 작동하지만 난 링크가 보여주는 '제거'하고 난 두 가지가있는 경우 만 표시로 선호 : 그것은 현재로
는 다음 내 양식에서 일부 코드 units_alloc 속성.
.field
= codeline.label :name, "Units Alloc"
%br/
= codeline.text_field :units_alloc, :precision => 6, :scale => 2, :size => 10,
:class => "ui-state-default"
- if :units_alloc.count > 1
= codeline.hidden_field :_destroy
= link_to "remove", '#', class: "remove_fields"
여기 내 오류입니다 :
이
내가 뭘하려 내가 대신 기호의 인수에 units_alloc 사용하는 경우, 난 여전히 오류가 발생 NoMethodError in Contracts#new
Showing /home/tom/rails_projects/tracking/app/views/contracts
/_codeline_fields.html.haml where line #9 raised:
undefined method `count' for :units_alloc:Symbol
:
NameError in Contracts#new
Showing /home/tom/rails_projects/tracking/app/views/contracts
/_codeline_fields.html.haml where line #9 raised:
undefined local variable or method `units_alloc' for
#<#<Class:0xadbde90>:0xa8956e8>
'codeline.units_alloc'을 사용하려고했으나 작동하지 않았고 동일한 오류가 표시되었습니다.
이 문제를 해결할 수있는 유용한 제안이나 조언이 있습니까?
감사합니다.
솔루션 : 감사 제임스 스콧 주니어
응용 프로그램/컨트롤러/contracts_controller.rb
def New
@show_remove = false
....
....
end
응용 프로그램/뷰/계약/_codelines_fields.html.haml
.field
= codeline.label :name, "Units Alloc"
%br/
= codeline.text_field :units_alloc, :precision => 6, :scale => 2, :size => 10,
:class => "ui-state-default"
- if @show_remove
= codeline.hidden_field :_destroy
= link_to "remove", '#', class: "remove_fields"
- else
- @show_remove = true
그리고 그 그랬 으면 ... 제거 버튼은 속성의 두 번째 및 후속 행에만 표시됩니다.
솔루션에 대한 James Scott Jr에게 감사드립니다. – thomasvermaak