You can push it to document_helper
or decorator
like :
module DocumentHelper
def form_render
return 'form_#{type}'
end
end
문제
I've got a form to build a Document
. That form needs adjusting depending on what type of Document
a user has chosen. At this point I've got a deferring kind of method in new.html.erb
that goes like this:
<%= render 'form_'+@template.label.downcase.parameterize.underscore %>
Which works fine but it's kinda difficult to manage though because when new types of documents are added I need to create actual HTML files and upload them.
Is there a better way to manage this kind of form generation? A view with hundreds of if
statements in it feels cumbersome too.
해결책
You can push it to document_helper
or decorator
like :
module DocumentHelper
def form_render
return 'form_#{type}'
end
end