轨道'设计编辑个人资料页面

时间:2015-04-01 12:01:00

标签: html ruby-on-rails devise

我试图将表单字段放入部分' _form.html.slim'但是当我这样做并且我在我的' edit.html.slim'中渲染部分时,表单没有完全呈现。在我的浏览器检查器中,它表示只有表单元素(不包括输入标签和提交按钮)才会在修改过的' edit.html.slim'中呈现。

以下是原版' edit.html.slim'

.row
  .small-8.columns.small-centered
    .form-panel
      p.welcome 
        | Edit 
        = resource_name.to_s.humanize

      = form_for(resource, as: resource_name, \ 
        url: registration_path(resource_name), html: {method: :put}) do |f|
        = devise_error_messages!

        .row
          .small-3.columns = f.label :username, class: 'right'
          .small-9.columns = f.text_field :username, autofocus: true

        .row
          .small-3.columns = f.label :email, class: 'right'
          .small-9.columns = f.text_field :email

        .row
          .small-3.columns = f.label :name, class: 'right'
          .small-9.columns = f.text_field :name

        .row
          .small-8.columns.small-centered
            = f.submit 'Save changes', class: 'button small expand'

      = link_to 'Back', :back

以下是经过修改的' edit.html.slim'这使得表单部分

.row
  .small-8.columns.small-centered
    .form-panel
      p.welcome 
        | Edit 
        = resource_name.to_s.humanize

      #profile_form
        = render 'form'

这是' _form.html.slim'部分

= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {method: :put}) do |f|
  = devise_error_messages!

    .row
      .small-3.columns = f.label :username, class: 'right'
      .small-9.columns = f.text_field :username, autofocus: true

    .row
      .small-3.columns = f.label :email, class: 'right'
      .small-9.columns = f.text_field :email

    .row
      .small-3.columns = f.label :name, class: 'right'
      .small-9.columns = f.text_field :name

    .row
      .small-8.columns.small-centered
        = f.submit 'Save changes', class: 'button small expand' 

更新: 我的代码中的错误是在" = devise_error_message!"下的div的缩进。由于slim很大程度上依赖于缩进,所以div被认为是" = devise_error_message的一部分!"不应该是这种情况。这是工作代码:

= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {method: :put}) do |f|
  = devise_error_messages!

  .row
    .small-3.columns = f.label :username, class: 'right'
    .small-9.columns = f.text_field :username, autofocus: true

  .row
    .small-3.columns = f.label :email, class: 'right'
    .small-9.columns = f.text_field :email

  .row
    .small-3.columns = f.label :name, class: 'right'
    .small-9.columns = f.text_field :name

  .row
    .small-8.columns.small-centered
      = f.submit 'Save changes', class: 'button small expand' 

0 个答案:

没有答案