设计编辑表单如何显示电子邮件地址

时间:2015-11-10 08:00:17

标签: ruby-on-rails ruby-on-rails-4 devise

我在设计视图中有以下编辑用户表单。我只想将文本显示为用户的电子邮件地址。不允许他编辑它。哪种显示方式最好?

<div class="pannel-body equal-padding">
            <%= form_for(resource, as: resource_name, url: registration_path(resource), :html => {:multipart => true, :class => 'form-horizontal', 'role' => 'form', method: :put}) do |f| %>
            <div class="form-group">
              <%= f.label :first_name, "First Name:".html_safe,:class => 'col-sm-3 control-label' %>
              <div class="col-sm-8">
                <%= f.text_field :first_name, :class => 'form-control' %>
                <%= show_errors(resource, :first_name).html_safe %>
              </div>
            </div>
            <div class="form-group">
              <%= f.label :last_name, "Last Name:".html_safe,:class => 'col-sm-3 control-label' %>
              <div class="col-sm-8">
                <%= f.text_field :last_name, :class => 'form-control' %>
                <%= show_errors(resource, :last_name).html_safe %>
              </div>
            </div>
              <div class="form-group">
                <%= f.label :display_photo, "Photo:".html_safe,:class => 'col-sm-3 control-label' %>
                <div class="col-sm-8">
                  <% if @user.display_photo.present? %>
                    <%= image_tag @user.display_photo.url(:large), :class => 'img-responsive', :width => 180 %>
                  <% else %>
                    <img src="<%= asset_path('default/user-photo.jpg') %>" width="180" alt="<%= current_user.name %>">
                    <br/>
                  <% end %>

                  <br/>
                  <%= f.file_field :display_photo, accept: 'image/png,image/gif,image/jpeg' %>
                  <p class="help-block">
                    Upload a cool picture of yourself.
                  </p>
                  <%= show_errors(resource, :display_photo).html_safe %>
                </div>
              </div>
              <div class="form-group">
                <%= f.label :email, "Email Address:<span class='mandatory'>*</span>".html_safe,:class => 'col-sm-3 control-label' %>
                <div class="col-sm-8">
                  <%= params %>
                  <%= f.text_field :email, :class => 'form-control' %>
                  <%= show_errors(resource, :email).html_safe %>
                </div>
              </div>

              <div class="form-group">
                <%= f.label :bio, "About:".html_safe,:class => 'col-sm-3 control-label' %>
                <div class="col-sm-8">
                  <%= f.text_area :bio, :class => 'form-control', :row => 5 %>
                  <%= show_errors(resource, :bio).html_safe %>
                </div>
              </div>

              <div class="form-group">
                <%= f.label :phone, "Phone Number:<span class='mandatory'>*</span>".html_safe,:class => 'col-sm-3 control-label' %>
                <div class="col-sm-8">
                  <%= f.text_field :phone, :class => 'form-control' %>
                  <%= show_errors(resource, :phone).html_safe %>
                </div>
              </div>

              <div class="form-group">
                <%= f.label :date_of_birth, "Date of Birth:<span class='mandatory'>*</span>".html_safe,:class => 'col-sm-3 control-label' %>
                <div class="col-sm-8">
                  <%= f.date_select :date_of_birth, { start_year: Date.today.year - 13, end_year: 100.years.ago.year} %>
                  <%= show_errors(resource, :date_of_birth).html_safe %>
                </div>
              </div>

              <div class="form-group">
                <div class="col-sm-offset-3 col-sm-8">
                  <button type="submit" class="btn btn-ph">Update Profile</button>
                </div>
              </div>
            <% end %>
          </div>

1 个答案:

答案 0 :(得分:1)

您可以使用html的disabled: true属性禁用文本字段。

e.g。

<%= f.text_field :email, :class => 'form-control' , disabled: true%>