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

update settings with devise controller #86

Closed
hcyildirim opened this issue Jul 16, 2018 · 0 comments
Closed

update settings with devise controller #86

hcyildirim opened this issue Jul 16, 2018 · 0 comments

Comments

@hcyildirim
Copy link

hcyildirim commented Jul 16, 2018

Hi,

I have model like below:

class User < ActiveRecord::Base  
  rolify

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  include DeviseTokenAuth::Concerns::User
  
  has_settings do |s|
    s.key :map, :defaults => { :units => 'miles' }
  end

  after_create :assign_default_role

  def assign_default_role
    self.add_role(:user) if self.roles.blank?
  end
end

And i want to update settings in my devise update. But i cant make it work. Here is registration controller:

module Overrides
    class RegistrationsController < DeviseTokenAuth::RegistrationsController
        def update
            params[:settings].each do |key, value|
                current_user.settings(key.to_sym).update_attributes! value
            end
        end
    end
end

And application controller:

class ApplicationController < ActionController::API
  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, :image, :gender, :birthday, settings: [map: [:units]]])
    devise_parameter_sanitizer.permit(:account_update, keys: [:name, :image, :gender, :birthday, settings: [map: [:units]]])
  end
end

But this setup gives me error: #<ActiveModel::ForbiddenAttributesError: ActiveModel::ForbiddenAttributesError>

There is no idea why it does not work. Can you help me?

Thank you.

@hcyildirim hcyildirim changed the title usage with devise update settings with devise controller Jul 16, 2018
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