2016-09-17 243 views
0

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

UsersController#create操作方法:

<%= render "https://stackoverflow.com/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 %> 

而我的新形式在用户浏览:

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 

我在色器件注册视图

<h1>New User</h1> 

<%= render 'form' %> 

<%= link_to 'Back', users_path %> 

我有这样的事情:

something like this

+0

目前还不清楚在屏幕截图中显示的路线是什么。这是'GET/users/new'还是'POST/users'的结果?这是否只发生在这个页面上? –

+0

更多信息。你是指向你的用户控制器而不是设计注册控制器?请确保您的routes.rb中包含以下内容:-----------> devise_for:users,:controllers => {:registrations =>“users/registrations”} \t ----- --->在我的情况下,我有一个名为users的文件夹。在某些文件中添加一些文本以查看哪个文件正在加载,或者同一文件是否加载两次。 – BKSpurgeon

回答

0

我觉得你呈现相同的部分。只需将其中一个“表单”文件的名称更改为其他名称即可。 Prob不是设计人员