我想禁用输入,因此一旦用户单击编辑,它就不可编辑。
student_form.html.haml
:
%div{:class => 'form-group row'}
%div{:class => 'form-group col-3'}
= label :student_id, :student_id, 'Student Id'
= text_field :student_id, :student_id, :maxlength => 6, :class => 'form-control'
edit.html.haml
:
= form_tag student_path(@student), :method => :put do
= render :partial => 'student_form'
= submit_tag 'Save Changes', :class => 'btn btn-primary'
%p
= render partial: 'shared/cancel_button', locals: {path: student_path(@student)}
您可以在disabled: true
中使用text_field
选项来禁用表单上的字段,因此它将仅显示值,不允许对其进行编辑。
student_form.html.haml:
= text_field :student_id, :student_id, :maxlength => 6, disabled: true, :class => 'form-control'
如果您在其他地方重用部分student_form
,并希望在该地方可编辑,则可以通过在locals
中传递此值,就像在其他部分中一样。