Ruby on rails Rails包含只读字段
我使用Cocoon来嵌套表单。对于已创建的Ruby on rails Rails包含只读字段,ruby-on-rails,cocoon-gem,Ruby On Rails,Cocoon Gem,我使用Cocoon来嵌套表单。对于已创建的task记录,我希望description为只读 项目/表格:: = simple_form_for @project do |f| = f.input :name = f.input :description %h3 Tasks #tasks = f.simple_fields_for :tasks do |task| = render 'task_fields', f: task .links
task
记录,我希望description
为只读
项目/表格::
= simple_form_for @project do |f|
= f.input :name
= f.input :description
%h3 Tasks
#tasks
= f.simple_fields_for :tasks do |task|
= render 'task_fields', f: task
.links
= link_to_add_association 'add task', f, :tasks
= f.submit
和_任务_字段:
.nested-fields
- if @task.description?
= f.text_field :description, disabled: true
- else
= f.input :description
= f.input :done, as: :boolean
= link_to_remove_association "remove task", f
当前,\u task\u字段
中的验证不起作用:与if
语句行中的nil:NilClass
的未定义方法。如何正确编写IF语句
对于已经创建的任务记录,我希望描述为
只读
你做错了。你应该可以用这样的方式进行检查
另外,通过使用disabled:true
,说明的值不会被提交,也不能通过params
传递。如果要在参数中设置描述值,请改用只读:true
.nested-fields
- unless f.object.new_record?
= f.text_field :description, readonly: true
- else
= f.input :description
= f.input :done, as: :boolean
= link_to_remove_association "remove task", f
对于已经创建的任务记录,我希望描述为
只读
你做错了。你应该可以用这样的方式进行检查
另外,通过使用disabled:true
,说明的值不会被提交,也不能通过params
传递。如果要在参数中设置描述值,请改用只读:true
.nested-fields
- unless f.object.new_record?
= f.text_field :description, readonly: true
- else
= f.input :description
= f.input :done, as: :boolean
= link_to_remove_association "remove task", f
您当前遇到的问题是什么?disabled:true
应该使用Cocoon
,我看到else
部分(=f.input:description
)没有disabled:true
的想法是让先前保存的记录的描述只读
,和可编辑呈现“新任务”时您当前遇到的问题是什么?已禁用:true
应与cococoon
一起使用,我看到其他
部分(=f.input:description
)未禁用功能:true
该功能的目的是让先前保存的记录的描述只读
,并在呈现“新任务”时可编辑