0

I am trying to add a drop down menu of User role in a Rails Application. I have configured the devise gem with default parameters. So far I have followed this link to add the user role attribute in User model and the views of Sign up and Log in. roles based authetication using enum

But I am facing an issue. Whenever the sign up operation is performed I get the following error message Error Message

In my Users model I have following code

    class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable

  enum role: [:manager, :developer, :QA]
end

In my view, I have following code for displaying the drop down menu

<div class="field">
    <%= f.label :role %><br />
    <%= f.select :role, User.roles %>
  </div>

My application controller contains following code

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

    def configure_permitted_parameters
      devise_parameter_sanitizer.permit(:sign_up, keys: [:username, :email, :password, :role])
    end
end
Aitzaz
  • 43
  • 7

2 Answers2

0

It would be more helpful if you uploaded your code, but trying without seeing it.. Do you have host variable set in environment.rb? Something such as

config.action_controller.default_url_options = { host: application url' }

Jack
  • 27
  • 1
  • 7
  • In environment.rb I just have following content: # Load the Rails application. require_relative 'application' # Initialize the Rails application. Rails.application.initialize! After appending your suggested line of code I got the error of "undefined local variable config" – Aitzaz May 16 '22 at 18:27
  • By the way I have added the related code as well for better improvement – Aitzaz May 16 '22 at 18:34
0

After experimenting a lot finally I was able to get rid of this error by changing my views a bit. The updated views looks like this

<div class="field">
    <%= f.label :role %><br />
    <%= f.select :role, ['role#1', 'role#2', 'role#3'] %>
  </div>
Aitzaz
  • 43
  • 7