ruby on rails - Devise multiple users - uninitialized constant UserRegistrationsController -
i relatively new rails , trying set multiple user types devise (borrowers , lenders). followed tutorial multiple user models ruby on rails , devise have separate registration routes 1 common login route
but keep coming error "uninitialized constant userregistrationscontroller".
here code have updated basic devise , locations (some of these moved/created based on understanding of tutorial may wrong):
in: app/controllers/users/registrations_controller.rb
class userregistrationscontroller < devise::registrationscontroller def create build_resource # customized code begin # crate new child instance depending on given user type user_type = params[:user][:user_type] resource.rolable = child_class.new(params[child_class.to_s.underscore.to_sym]) # first check if child instance valid # cause if , parent instance valid # it's being saved @ once valid = resource.valid? valid = resource.rolable.valid? && valid # customized code end if valid && resource.save # customized code if resource.active_for_authentication? set_flash_message :notice, :signed_up if is_navigational_format? sign_in(resource_name, resource) respond_with resource, :location => redirect_location(resource_name, resource) else set_flash_message :notice, :inactive_signed_up, :reason => inactive_reason(resource) if is_navigational_format? expire_session_data_after_sign_in! respond_with resource, :location => after_inactive_sign_up_path_for(resource) end else clean_up_passwords(resource) respond_with_navigational(resource) { render :new } end end end
in: app/controllers/users_controller.rb
class userscontroller < applicationcontroller def show @user = user.find(params[:id]) @pins = @user.pins.page(params[:page]).per_page(20) end end
in: app/models/borrower.rb
class borrower < activerecord::base has_one :user, :as => :rolable has_many :pins end
in: app/models/lender.rb
class lender < activerecord::base has_one :user, :as => :rolable has_many :pins end
in: app/models/user.rb
class user < activerecord::base # include default devise modules. others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable , :omniauthable devise :database_authenticatable, :registerable, :rememberable, :trackable, :validatable #:recoverable, # setup accessible (or protected) attributes model attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :description # attr_accessible :title, :body belongs_to :rolable, :polymorphic => true has_many :pins end
in: app/views/devise/user_registrations/_borrower_fields.html
<div><%= f.label :label_name %><br /> <%= f.text_field :label_name %></div>
in: app/views/devise/user_registrations/_lender_fields.html
<div><%= f.label :label_name %><br /> <%= f.text_field :label_name %></div>
in: app/views/devise/user_registrations/new.html.erb
<h2>sign up</h2> <% # customized code begin params[:user][:user_type] ||= 'borrower' if ["borrower", "lender"].include? params[:user][:user_type].downcase child_class_name = params[:user][:user_type].downcase.camelize user_type = params[:user][:user_type].downcase else child_class_name = "borrower" user_type = "borrower" end resource.rolable = child_class_name.constantize.new if resource.rolable.nil? # customized code end %> <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), html: {class: 'form-horizontal'}) |f| %> <%= f.error_notification %> <%= f.input :name %> <%= f.input :email %> <%= f.input :password %> <%= f.input :password_confirmation %> <%= f.input :description, label: "tell yourself" %> <% # customized code begin %> <%= fields_for resource.rolable |rf| %> <% render :partial => "#{child_class_name.underscore}_fields", :locals => { :f => rf } %> <% end %> <%= hidden_field :user, :user_type, :value => user_type %> <% # customized code end %> <div class="form-actions"> <%= f.submit "sign up", class: "btn btn-primary" %> </div> <% end %> <%= render "devise/shared/links" %>
in: config/locales/routes.rb:
get "users/show" resources :pins devise_for :users, :controllers => { :registrations => 'userregistrations' } match 'users/:id' => 'users#show', :as => :user 'about' => 'pages#about' 'clothing' => 'pages#clothing' 'bags' => 'pages#bags' 'shoes' => 'pages#shoes' 'stylefeed' => 'pages#stylefeed' 'accessories' => 'pages#accessories' 'designers' => 'pages#designers' root :to => 'pins#index' match 'borrower/sign_up' => 'user_registrations#new', :user => { :user_type => 'borrower' } match 'lender/sign_up' => 'user_registrations#new', :user => { :user_type => 'lender' }
i added rolabe id , rolable type users table , generated registrations controller.
does have idea going wrong? thanks!!
rails autoload failing find file class. rename userregistrationscontroller
users::registrationscontroller
Comments
Post a Comment