报名表格

时间:2016-09-17 00:32:53

标签: ruby-on-rails

我正在使用Devise。显示注册表单时,它将被呈现两次。

我的UsersController#create操作方法:

def create
  @user = User.new(user_params)
  respond_to do |format|
    if @user.save
      format.html { redirect_to @user, notice: 'User was successfully created.' }
      format.json { render :show, status: :created, location: @user }
    else
      format.html { render :new }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end

我的设计注册视图:

<%= render "/users/form"%>

用户_form

<style>
   .center {
    width: 400px; 
    padding: 10px;
    margin: auto; 
   }
</style>
<div class="center">
  <%= form_for(@user) do |f| %>
    <% if @user.errors.any? %>
      <div id="error_explanation">
        <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
        <ul>
        <% @user.errors.full_messages.each do |message| %>
          <li><%= message %></li>
        <% end %>
        </ul>
      </div>
    <% end %>

<md-input-container>
    <%= f.label :email %><br>
    <%= f.email_field :email %>
  </md-input-container>

  <md-input-container>
    <%= f.label :token %><br>
    <%= f.text_field :token %>
  </md-input-container>

  <md-input-container>
    <%= f.label :name %><br>
    <%= f.text_field :name %>
  </md-input-container>

  <md-input-container>
    <%= f.label :password %>
    <%= f.password_field :password, autocomplete: "off" %>
  </md-input-container>

  <md-input-container>
    <%= f.label :password_confirmation %><br />
    <%= f.password_field :password_confirmation, autocomplete: "off" %>
  </md-input-container>



  <md-input-container>
              <%= f.label :appointment %><br>
          <md-select ng-model="ctrl.userAppointment">
            <md-option><em><%= f.select(:appointment_id, options_for_select( Appointment.all.map{| c | [c.name, c.id] } ), :prompt => "Select appointment") %></em></md-option>
          </md-select>
        </md-input-container>

  <div class="actions">
      <div>
        <md-button type="submit"><%= f.submit %></md-button>
      </div>
</div>
  </div>
<% end %>

我的新表单在用户视图中:

<h1>New User</h1>

<%= render 'form' %>

<%= link_to 'Back', users_path %>

我有这样的事情:

something like this

1 个答案:

答案 0 :(得分:0)

我认为你渲染的部分相同。只需更改其中一个&#34;表单&#34;文件到别的东西。问题不是设计一个