Ruby on rails 带Desive的AngularJS-不可加工实体

Ruby on rails 带Desive的AngularJS-不可加工实体,ruby-on-rails,angularjs,devise,Ruby On Rails,Angularjs,Devise,我正试图通过Rails4中的AngularJs+Desive创建一个注册过程 我正在跟随这本书->AngularJS骑行轨道 /用户/注册\u controller.rb class Users::RegistrationsController < DeviseController prepend_before_filter :require_no_authentication, only: [ :new, :create, :cancel ] prepend_before_f

我正试图通过Rails4中的AngularJs+Desive创建一个注册过程

我正在跟随这本书->AngularJS骑行轨道

/用户/注册\u controller.rb

  class Users::RegistrationsController < DeviseController
  prepend_before_filter :require_no_authentication, only: [ :new, :create, :cancel ]
  prepend_before_filter :authenticate_scope!, only: [:edit, :update, :destroy]

  # GET /resource/sign_up
  def new
    build_resource({})
    respond_with self.resource
  end

  # POST /resource
  def create
    build_resource(sign_up_params)

    resource_saved = resource.save
    yield resource if block_given?
    if resource_saved
      sign_in resource
      render status: 200,
      json: {
          success: true,
          info: "Registered",
          data: {
          user: resource,
          auth_token: current_user.authentication_token
        }
      }
    else
    # Otherwise fail
    render status: :unprocessable_entity,
    json: {
      success: false,
      info: resource.errors,
      data: {}
    }

    puts resource.errors.full_messages
    end
  end

  # GET /resource/edit
  def edit
    render :edit
  end

  # PUT /resource
  # We need to use a copy of the resource because we don't want to change
  # the current user in place.
  def update
    self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
    prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)

    resource_updated = update_resource(resource, account_update_params)
    yield resource if block_given?
    if resource_updated
      if is_flashing_format?
        flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
          :update_needs_confirmation : :updated
        set_flash_message :notice, flash_key
      end
      sign_in resource_name, resource, bypass: true
      respond_with resource, location: after_update_path_for(resource)
    else
      clean_up_passwords resource
      respond_with resource
    end
  end

  # DELETE /resource
  def destroy
    resource.destroy
    Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
    set_flash_message :notice, :destroyed if is_flashing_format?
    yield resource if block_given?
    respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
  end

  # GET /resource/cancel
  # Forces the session data which is usually expired after sign
  # in to be expired now. This is useful if the user wants to
  # cancel oauth signing in/up in the middle of the process,
  # removing all OAuth session data.
  def cancel
    expire_data_after_sign_in!
    redirect_to new_registration_path(resource_name)
  end

  protected

  def update_needs_confirmation?(resource, previous)
    resource.respond_to?(:pending_reconfirmation?) &&
      resource.pending_reconfirmation? &&
      previous != resource.unconfirmed_email
  end

  # By default we want to require a password checks on update.
  # You can overwrite this method in your own RegistrationsController.
  def update_resource(resource, params)
    resource.update_with_password(params)
  end

  # Build a devise resource passing in the session. Useful to move
  # temporary session data to the newly created user.
  def build_resource(hash=nil)
    self.resource = resource_class.new_with_session(hash || {}, session)
  end

  # Signs in a user on sign up. You can overwrite this method in your own
  # RegistrationsController.
  def sign_up(resource_name, resource)
    sign_in(resource_name, resource)
  end

  # The path used after sign up. You need to overwrite this method
  # in your own RegistrationsController.
  def after_sign_up_path_for(resource)
    after_sign_in_path_for(resource)
  end

  # The path used after sign up for inactive accounts. You need to overwrite
  # this method in your own RegistrationsController.
  def after_inactive_sign_up_path_for(resource)
    scope = Devise::Mapping.find_scope!(resource)
    router_name = Devise.mappings[scope].router_name
    context = router_name ? send(router_name) : self
    context.respond_to?(:root_path) ? context.root_path : "/"
  end

  # The default url to be used after updating a resource. You need to overwrite
  # this method in your own RegistrationsController.
  def after_update_path_for(resource)
    signed_in_root_path(resource)
  end

  # Authenticates the current scope and gets the current resource from the session.
  def authenticate_scope!
    send(:"authenticate_#{resource_name}!", force: true)
    self.resource = send(:"current_#{resource_name}")
  end

  def sign_up_params
    devise_parameter_sanitizer.sanitize(:sign_up)
  end

  def account_update_params
    devise_parameter_sanitizer.sanitize(:account_update)
  end
end
routes.rb

namespace :api, defaults: { format: 'json' } do

    devise_for :users,
      :controllers => {
        registrations: "users/registrations"
      }

    scope module: :v1 do
      resources :campaigns
    end
  end
现在,它不是保存,而是说回滚

Started GET "/" for 127.0.0.1 at 2014-08-06 03:04:18 +0800
Processing by MainController#show as HTML
  Rendered main/show.html.haml within layouts/application (0.1ms)
Completed 200 OK in 20ms (Views: 19.4ms | ActiveRecord: 0.0ms)


Started POST "/api/users" for 127.0.0.1 at 2014-08-06 03:04:24 +0800
Processing by Users::RegistrationsController#create as JSON
  Parameters: {"user"=>{"email"=>"shielas@sourcepad.com", "password"=>"[FILTERED]"}, "registration"=>{"user"=>{"email"=>"shielas@sourcepad.com", "password"=>"[FILTERED]"}}}
   (0.2ms)  BEGIN
   (0.2ms)  ROLLBACK
Email can't be blank
Password can't be blank
Completed 422 Unprocessable Entity in 26ms (Views: 0.9ms | ActiveRecord: 3.7ms)
我检查了resource.errors.full_消息,它说电子邮件不能为空,密码不能为空


我确信我正在传递数据。

在你的控制器中,我们可以看到你的注册参数吗?@JTG刚刚用默认值更新了它。你知道吗?您使用的是railsapigem还是rails本身?似乎是允许的参数问题
namespace :api, defaults: { format: 'json' } do

    devise_for :users,
      :controllers => {
        registrations: "users/registrations"
      }

    scope module: :v1 do
      resources :campaigns
    end
  end
Started GET "/" for 127.0.0.1 at 2014-08-06 03:04:18 +0800
Processing by MainController#show as HTML
  Rendered main/show.html.haml within layouts/application (0.1ms)
Completed 200 OK in 20ms (Views: 19.4ms | ActiveRecord: 0.0ms)


Started POST "/api/users" for 127.0.0.1 at 2014-08-06 03:04:24 +0800
Processing by Users::RegistrationsController#create as JSON
  Parameters: {"user"=>{"email"=>"shielas@sourcepad.com", "password"=>"[FILTERED]"}, "registration"=>{"user"=>{"email"=>"shielas@sourcepad.com", "password"=>"[FILTERED]"}}}
   (0.2ms)  BEGIN
   (0.2ms)  ROLLBACK
Email can't be blank
Password can't be blank
Completed 422 Unprocessable Entity in 26ms (Views: 0.9ms | ActiveRecord: 3.7ms)