由simple_form生成的脚手架模板

时间:2019-03-09 18:44:47

标签: ruby-on-rails slim-lang

Rails 5.2.2
Ruby 2.6

我安装了宝石slim_rails和引导程序。

我添加了simple_form,并做到了:

rails g simple_form:install bootstrap

我最终在lib / templates / slim / scaffold中创建了一个模板(_form.html.slim),其中包含以下内容:

= simple_form_for(@<%= singular_table_name %>) do |f|
  = f.error_notification
  = f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present?

  .form-inputs
<%- attributes.each do |attribute| -%>
    = f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %>
<%- end -%>

  .form-actions
    = f.button :submit

为什么这是.erb和.slim的混合,并且会起作用?我应该将.erb零件转换为.slim吗?

编辑

这是我修改模板的方式:

= simple_form_for(@<%= singular_table_name %>) do |f|
  = f.error_notification
  = f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present?

  .form-inputs
    - attributes.each do |attribute|
      = f.#{attribute.reference? ? :association : :input} :#{attribute.name}

.form-actions     = f.button:提交

0 个答案:

没有答案