Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't permit parameters in rails engine #731

Closed
steffenschmidt opened this issue Sep 11, 2016 · 1 comment
Closed

Can't permit parameters in rails engine #731

steffenschmidt opened this issue Sep 11, 2016 · 1 comment

Comments

@steffenschmidt
Copy link

I have a rails 5 api only app where I use devise_token_auth in my core engine. Unfortunately I cannot set parameters which I would allow to set in registration process

rails (5.0.0.1)
devise (4.2.0)
devise_token_auth (0.1.39)

That is my engine application controller (RAILS_ROOT/engines/core/app/controllers/project_name/application_controller.rb):

module ProjectName
  class ApplicationController < ActionController::Base
    protect_from_forgery with: :null_session

    include DeviseTokenAuth::Concerns::SetUserByToken

    before_action :configure_permitted_parameters, if: :devise_controller?

  protected

    def configure_permitted_parameters
      devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
    end

  end
end

That is my user model inside my engine (RAILS_ROOT/engines/core/app/models/project_name/user.rb):

module ProjectName
  class User < ApplicationRecord
    devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :trackable, :validatable

    include DeviseTokenAuth::Concerns::User

    validates :name, presence: true
  end
end

My routes are set to the following:

ProjectName::Core::Engine.routes.draw do
  mount_devise_token_auth_for "ProjectName::User", at: "auth"
end

When requesting the route to create an user I get the following info in the log file:

Started POST "/auth" for ::1 at 2016-09-11 16:36:52 +0200
Processing by DeviseTokenAuth::RegistrationsController#create as JSON
  Parameters: {"email"=>"[email protected]", "password"=>"[FILTERED]", "name"=>"Test User", "registration"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "name"=>"Test User"}}
Unpermitted parameters: name, registration

I realized that the before_action configure_permitted_parameters will not be called. But why? Even if I remove the if-condition the engine controller ignores the method.

How can I allow a users name in the registration process? Can anyone help me? Thanks in advance?

@steffenschmidt
Copy link
Author

I solved this by setting config.parent_controller = "ProjectName::ApplicationController" to my devise.rb initializer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant