0
MVC에 따라 더 나은 (적절한) 방법은 무엇입니까? 여기 상황입니다 : 내 형태로 collection_select이모델에서 다시 코딩, 도우미 메서드를 사용할 수 없습니다
하고, 그러나 나는이 같은 (옵션의 텍스트를 참고, 4 ARG)
#Form.html.haml
= form_for(@payment) do |f|
= f.collection_select(:invoice_id, Invoice.due, :id, :number + ' ' + money(:amount_due))
을 꿔, 잘 작동 내가 아는 한 기호를 연결할 수 없으므로 작동하지 않습니다. 그래서, 나는이에 의존 : 나는 모델에서 도우미 메서드를 호출하는 것을 시도되지 않은 경우 일 것이다
#Form.html.haml
= form_for(@payment) do |f|
= f.collection_select(:invoice_id, Invoice.due, :id, :number_with_amount_due)
#Invoice.rb
def number_with_amount_due
"##{number} (#{money(amount_due)})"
end
.
그럼 어떻게해야합니까? 보기에서 선택 텍스트를 연결하는 것이 좋을 수도 있지만 가능하지 않은 경우 Rails에서 적절한 MVC를 유지하면서 수행하려는 작업을 어떻게 달성 할 수 있습니까?
다음과 같은 이유로 작동하지 않습니다 :'= form_for (@payment) do | f |'는 f입니다. 이 질문을 원래 질문에 추가하겠습니다. 의견을 주셔서 감사합니다 –
그럼'has_one : invoice'는 f.object.invoice.number와 f.object.invoice.amount_due –
'has_one'이 아닌'belongs_to : invoice'입니다. 귀하의 코드 (f.object.invoice.number)를 시도 할 때 오류가 발생했습니다 : 'undefined method'number for nil : NilClass' –