User roles with devise Modular Rails 4 -


i've been struggling issue weeks. goal create 3 different types of users. regular, page , venue. upon registration user able select role [regular,page or venue]. depending on role user chooses they're redirected edit profile page have fill in additional information. depending on user role, user provided specific layout , separate root.

example : user chooses role via registration form once signed user redirected edit form fill in additional info name, location. ( trying find way make required, before user can interact platform have fill in additional information not required on registration form. ideas on amazing.)

so root user role specific view.

also application being built within engines, using modular wa

what have :

by following tutorial able set user roles simply. , wrapping head around using cancan. http://www.mashpy.me/rails/role-based-registration-with-devise-and-cancan-using-ruby-on-rails/.

user.rb

module m0ve class user < activerecord::base    # include default devise modules. others available are:   # :confirmable, :lockable, :timeoutable , :omniauthable   devise :database_authenticatable, :registerable,          :recoverable, :rememberable, :trackable, :validatable  validates :user_name, presence: true, length: { minimum: 4, maximum: 12 } validates :email, presence: true validates :role, presence: true  has_many :posts, dependent: :destroy has_many :comments, dependent: :destroy  roles = %w[regular page venue]  def role_symbols       [role.to_sym] end 

application controller

module m0ve   class applicationcontroller < actioncontroller::base       before_filter :authenticate_user!  protect_from_forgery with: :exception    protected   def after_sign_up_path_for(resource)       if current_user.role? :regular          regular_index        end   end      end end 

registration controller

module m0ve class m0ve::registrationscontroller < devise::registrationscontroller   private    def sign_up_params     params.require(:user).permit(:email, :user_name, :password, :password_confirmation, :role)   end    def account_update_params     params.require(:user).permit(:email, :user_name, :password, :password_confirmation, :current_password)   end end end 

routes

m0ve::core::engine.routes.draw    devise_for :users, class_name: "m0ve::user",module: :devise,:controllers => { registrations: 'm0ve/registrations' }    resources :posts    resources :comments end  end 

sorry if missed information please let me know need clarify , i'll appreciate .

you use rolify gem devise , cancan or cancancan manage multiple role based authorization.

with effort should able create , manage roles well.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -