I have a rails app, using devise for users. I have 2 types of users that share some fields and then have their own. I made polymorphic models for the 2 types. When I added fields to the base devise user, the form for adding a new user doesn't seem to be recognizing the new fields.
devise user
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
belongs_to :meta, polymorphic: true
end
polymorphic artist model
class Artist < ActiveRecord::Base
has_one :user, as: :meta, dependent: :destroy
has_and_belongs_to_many :artist_expertises
accepts_nested_attributes_for :user
has_many :connections
has_many :teachers, through: :connections
end
overwriting devise registrations
class RegistrationsController < Devise::RegistrationsController
private
def sign_up_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation)
end
def account_update_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password)
end
end
routes
Rails.application.routes.draw do
...
resources :artists
resources :teachers
devise_for :users, :controllers => { registrations: 'registrations' }
...
end
Then on the following _form that is used in the new page for an artist is fine for the email and password fields from devise by default. the next user_fields.label for the :first_name field that I added to the users table errors with (undefined local variable or method `user_fields' for #<#:0x007f9c81b3a108> Did you mean? number_field)
views/artist/_form.html.erb (rendered in the new view)
<%= form_for(setup_artist(@artist)) do |f| %>
<% if @artist.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@artist.errors.count, "error") %> prohibited this artist from being saved:</h2>
<ul>
<% @artist.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.fields_for :user do |user_fields| %>
<div class="field">
<%= user_fields.label :email %>
<%= user_fields.text_field :email %>
</div>
<div class="field">
<%= user_fields.label :password %>
<%= user_fields.text_field :password %>
</div>
<% end %>
<div class="field">
<%= user_fields.label :first_name %><br />
<%= user_fields.text_field :first_name %>
</div>
<div class="field">
<%= user_fields.label :last_name %><br />
<%= user_fields.text_field :last_name %>
</div>
<div class="field">
<%= f.label :inspiration %><br>
<%= f.text_area :inspiration %>
</div>
<div class="field">
<%= f.label "Area of Expertise" %><br />
<%= f.collection_check_boxes :artist_expertise_ids, ArtistExpertise.all, :id, :name do |b| %>
<div class="collection-check-box">
<%= b.check_box %>
<%= b.label %>
</div>
<% end %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>