Jeremy Thomas
Jeremy Thomas

Reputation: 6674

Rails 4: Devise Invitable Unpermitted Parameter

I am using the Devise Invitable gem to invite users and after creating the user, I create a client with a user_id that is equal the id of the user that was just created

class User < ActiveRecord::Base
    after_create :create_client

    def create_client
        new_client = Client.new()
        new_client.user_id = self.id
        new_client.save
    end
end

This works, but once I tried to add location_id to the parameters, I see:

Unpermitted parameter: location_id

Here is the new method with location_id

def create_client
    new_client = Client.new()
    new_client.user_id = self.id
    new_client.location_id = self.location_id
    new_client.save
end

I've read a lot of responses about this issue, but cannot seem to find a real solution to whitelist this parameter. Does anyone have a method that works in Rails 4 with Devise 3.5

Upvotes: 1

Views: 396

Answers (1)

Jeremy Thomas
Jeremy Thomas

Reputation: 6674

It was crucial to whitelist the params for :invite and not just for :accept_invitation. The following worked when I added it to my application_controller:

def configure_permitted_parameters
    devise_parameter_sanitizer.for(:accept_invitation) << [:location_id]
    devise_parameter_sanitizer.for(:invite) << [:location_id]
end

Upvotes: 3

Related Questions