You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
hcyildirim
changed the title
usage with devise
update settings with devise controller
Jul 16, 2018
Hi,
I have model like below:
And i want to update settings in my devise update. But i cant make it work. Here is registration controller:
And application controller:
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.
The text was updated successfully, but these errors were encountered: