覆盖设计注册控制器的问题

时间:2017-09-22 09:46:54

标签: ruby-on-rails ruby forms devise haml

我实际上试图覆盖我的设计注册控制器,但我遇到了一个问题。当我尝试从表单调用自定义注册控制器时,我的自定义注册控制器不会被调用。

routes.rb中:

http.get(..., { headers: new HttpHeaders({ useAuth: 'A' }) });

应用/控制器/用户/ registrations_controller.rb

  intercept(req, next) {
    if (req.headers.get('useAuth') === 'A') ...
    else if (req.headers.get('useAuth') === 'B') ...
    else ...

    req.headers = req.headers.delete('useAuth'));
  }

application_controller.rb

Rails.application.routes.draw do
   devise_for :users, controllers: { registrations: 'users/registrations' }
end

当我从邮递员那里给它打电话时,我得到了那些日志:

class Users::RegistrationsController < Devise::RegistrationsController
  skip_before_action :verify_authenticity_token

  #POST /users
  def create
    puts "ENTER"
    #super
  end
end

但是当我从这个Haml表格中调用它时:

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception, prepend: true
  before_action :configure_permitted_parameters, if: :devise_controller?

protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:firstname, :lastname, :address, :phone, :gender])
  end
end

我得到那些日志:

Started POST "/users" for 127.0.0.1 at 2017-09-22 11:32:16 +0200
Processing by Users::RegistrationsController#create as */*
  Parameters: {"user"=>{"email"=>"test@gmail.com", "password"=>"[FILTERED]", "firstname"=>"test", "lastname"=>"test1", "phone"=>"123456789", "address"=>"test", "gender"=>"test"}}
ENTER
No template found for Users::RegistrationsController#create, rendering head 
:no_content
Completed 204 No Content in 1065ms (ActiveRecord: 0.0ms)

在最后一种情况下,我不知道发生了什么,我的日志中没有“输入”。唯一的,我注意到改变了:

.form-zone-container .form-zone %form.form{"accept-charset" => "UTF-8", :action => "/users", :enctype => "multipart/form-data", :method => "post"} .title Personal informations .radio-btn #form_gender %input#form_gender_1.check{"aria-required" => "true", :name => "user[gender]", :required => "required", :type => "radio", :value => "Male"}/ %label.required{:for => "form_gender_1"} Male %input#form_gender_0.check{"aria-required" => "true", :name => "user[gender]", :required => "required", :type => "radio", :value => "Female"}/ %label.required{:for => "form_gender_0"} Female %input{:name => "user[firstname]", :placeholder => "name", :type => "text", :value => (@params[:user]['firstname'] if @params[:user] && @params[:user]['firstname'])}/ %input{:name => "user[lastname]", :placeholder => "Last name", :type => "text", :value => (@params[:user]['lastname'] if @params[:user] && @params[:user]['lastname'])}/ %input{:name => "user[email]", :placeholder => "Email", :type => "email", :value => (@params[:user]['email'] if @params[:user] && @params[:user]['email'])}/ %input{:name => "user[password]", :placeholder => "password", :type => "password"}/ %input{:class => "confirm_password", :placeholder => "Confirm your password", :type => "password"}/ %input{:name => "user[phone]", :placeholder => "Phone", :type => "tel"}/ %input.place{:name => "user[address]", :placeholder => "Address", :type => "text", :value => (@params[:meeting]['address'] if @params[:meeting] && @params[:meeting]['address'])}/ %a.little-green-btn{:onclick => "$(this).closest('form').submit()"} Send Started POST "/users" for 127.0.0.1 at 2017-09-22 11:39:37 +0200 Processing by Users::RegistrationsController#create as HTML Parameters: {"user"=>{"gender"=>"Male", "firstname"=>"test", "lastname"=>"test", "email"=>"test@gmail.com", "password"=>"[FILTERED]", "phone"=>"test", "address"=>"test"}} User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 2], ["LIMIT", 1]] Redirected to http://localhost:3000/ Filter chain halted as :require_no_authentication rendered or redirected Completed 302 Found in 35ms (ActiveRecord: 3.8ms) Started GET "/" for 127.0.0.1 at 2017-09-22 11:39:37 +0200 Processing by Rails::WelcomeController#index as HTML Rendering /Users/admin/.rvm/gems/ruby-2.4.1@global/gems/railties-5.1.4/lib/rails/templates/rails/welcome/index.html.erb Rendered /Users/admin/.rvm/gems/ruby-2.4.1@global/gems/railties-5.1.4/lib/rails/templates/rails/welcome/index.html.erb (2.5ms) Completed 200 OK in 37ms (Views: 5.1ms | ActiveRecord: 0.0ms)

希望有人可以帮我解决这个问题。

提前感谢,

更新

佣金路线

Processing by Users::RegistrationsController#create as */*

尝试使用form_for:

Processing by Users::RegistrationsController#create as HTML

仍然得到相同的结果。

0 个答案:

没有答案