I have a form with multiple "li" elements that contain form fields, where the only thing that varies is one word in multiple placee. Example:
我有一个包含多个“li”元素的表单,其中包含表单字段,其中唯一不同的是多个placee中的一个单词。例:
li
= f.label :answer_tax, 'Tax'
= f.text_field :answer_tax,
'ng-model' => 'Form.tax',
'ng-pattern' => '{{pattern}}',
'ng-focus' => 'initFields(Form.tax)',
'ng-blur' => 'updateScore(Form.tax, "tax")'
li
= f.label :answer_chase, 'Chase'
= f.text_field :answer_chase,
'ng-model' => 'Form.chase',
'ng-pattern' => '{{pattern}}',
'ng-focus' => 'initFields(Form.chase)',
'ng-blur' => 'updateScore(Form.chase, "chase")'
I would like to create a partial that takes each word from an array and generates the form fields. Where is the best place to do this (helper?) and how would I go about doing it? Thank you for your time.
我想创建一个部分,从数组中获取每个单词并生成表单字段。最好的地方在哪里(帮手?)我将如何去做?感谢您的时间。
1 个解决方案
#1
1
You could just do it in the view, you don't even need to use a partial if you feel this is simpler (i've assumed you're using HAML? If I'm right, you should have % on the li tag?):
您可以在视图中执行此操作,如果您觉得这样更简单,您甚至不需要使用部分(我假设您正在使用HAML?如果我是对的,您应该在li标签上有% ?):
- %w{ tax chase }.each do |field_name|
%li
= f.label "answer_#{field_name}".to_sym, field_name.capitalize
= f.text_field "answer_#{field_name}".to_sym,
'ng-model' => "Form.#{field_name}",
'ng-pattern' => '{{pattern}}',
'ng-focus' => "initFields(Form.#{field_name})',
'ng-blur' => "updateScore(Form.#{field_name}, \"#{field_name}\")"
#1
1
You could just do it in the view, you don't even need to use a partial if you feel this is simpler (i've assumed you're using HAML? If I'm right, you should have % on the li tag?):
您可以在视图中执行此操作,如果您觉得这样更简单,您甚至不需要使用部分(我假设您正在使用HAML?如果我是对的,您应该在li标签上有% ?):
- %w{ tax chase }.each do |field_name|
%li
= f.label "answer_#{field_name}".to_sym, field_name.capitalize
= f.text_field "answer_#{field_name}".to_sym,
'ng-model' => "Form.#{field_name}",
'ng-pattern' => '{{pattern}}',
'ng-focus' => "initFields(Form.#{field_name})',
'ng-blur' => "updateScore(Form.#{field_name}, \"#{field_name}\")"