I have a rails 4 app running devise 3.x and I am having trouble adding a :first_name
column to my Player model. I have 2 separate models that inherit from a User
model - Player
and Coach
I followed this 12 spokes post but am having trouble rendering the registration form in development mode.
I have a class PlayerParameterSanitizer
to override the devise signup action and add the :first_name
parameter
class PlayerParameterSanitizer < Devise::ParameterSanitizer
def sign_up
default_params.permit(:type, :email, :password, :password_confirmation, :first_name)
end
end
and I create a new object of this class in the application controller
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
protected
def devise_parameter_sanitizer
if resource_class == Player
PlayerParameterSanitizer.new(Player,:player,params)
elsif resource_class == Coach
CoachParameterSanitizer.new(Coach,:coach,params)
else
super
end
end
end
I'm loading the sanitizers in an initializer in config/initializers/sanitizers.rb
require "#{Rails.application.root}/lib/player_sanitizer.rb"
Yet, I'm still getting the
undefined method `first_name' for #<Player:0x00000101cafab0>
on the view/players/registrations/new.html.erb
page. What am I missing here?
update
db schema
create_table "players", force: true do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.string "first_name"
end
Update #2
devise_for :players, :controllers => {:registrations => "players/registrations",
:sessions => "players/sessions",
:passwords => "players/passwords"}
models for unrelated sanity
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
Player class inheriting from User.
class Player < User
end
Update #3
I shouldn't be using STI in this fashion, I don't think.
I want Coach and Player to share Devise Auth Functionality but Player will have additional fields to Coach (club, position, year, etc.)
With STI for rails 4 all attributes would be stored on the User table. But this means a Coach would have those fields but be saved in it's table as having nil for stuff like position, current club, etc.
That seems incorrect..
Basically, I want both Coach and Player to inherit from User so as to achieve devise functionality. But, I want Player to have several fields in addition to that of Coach.