Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 Rails 4.0和Desive的强大参数_Ruby On Rails 4_Devise_Strong Parameters - Fatal编程技术网

Ruby on rails 4 Rails 4.0和Desive的强大参数

Ruby on rails 4 Rails 4.0和Desive的强大参数,ruby-on-rails-4,devise,strong-parameters,Ruby On Rails 4,Devise,Strong Parameters,我正在使用Rails 4.2和Desive。请求类型将始终为JSON。我的注册控制器如下所示 class Users::RegistrationsController < Devise::RegistrationsController before_filter :configure_sign_up_params, only: [:create] def create if request.format(request) == "application/json"

我正在使用Rails 4.2和Desive。请求类型将始终为JSON。我的注册控制器如下所示

class Users::RegistrationsController < Devise::RegistrationsController
  before_filter :configure_sign_up_params, only: [:create]

  def create
    if request.format(request) == "application/json"
      build_resource(sign_up_params)
      if resource.save
        render :json => {:success => "true", :message => "Thank You For Registering."}
      else
        render :json => {:success => "false", :message => resource.errors.full_messages}
      end
    else
      super
    end
  end

  protected

  def configure_sign_up_params
    devise_parameter_sanitizer.for(:sign_up) do |u|
      u.permit(:email, :password, :password_confirmation)
    end
  end

end
它产生的错误是控制器无法识别电子邮件和密码字段,并且总是返回错误,如:

["Email can't be blank","Password can't be blank"]

发生这种情况是因为我在代码中写的愚蠢吗?请帮助

您的
配置\u注册\u参数
方法必须是这样才能工作的

def configure_sign_up_params
  devise_parameter_sanitizer.for(:registration) do |u|
    u.permit(:email, :password, :password_confirmation)
  end
end
如果您可以看到您发布的控制台内容,则它包含一个散列,其中包含
注册
作为密钥:

"registration"=>{"email"=>"test123@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}
"registration"=>{"email"=>"test123@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}