Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm in similar shoes as you, after trying all sorts of approaches I went with a single User model, which would belong to polymorphic roles. This seems like the simplest way to achieve single-login. </p> <p>The User model would contain the information specific to log-in only. </p> <p>The Role model would store fields specific to each role, as well as other associations specific to the role. </p> <p>New registrations would be customized for each user type (roles) via individual controllers, and then building nested attributes for the User. </p> <pre><code>class User &lt; ActiveRecord::Base #... devise code ... belongs_to :role, :polymorphic =&gt; true end class Member &lt; ActiveRecord::Base attr_accessible :name, :tel, :city #etc etc.... attr_accessible :user_attributes #this is needed for nested attributes assignment #model specific associations like has_many :resumes has_one :user, :as =&gt; :role, dependent: :destroy accepts_nested_attributes_for :user end </code></pre> <p>Routes -- just regular stuff for the Member model. </p> <pre><code>resources :members #maybe make a new path for New signups, but for now its new_member_path </code></pre> <p>Controller -- you have to build_user for nested attributes</p> <pre><code>#controllers/members_controller.rb def new @member = Member.new @member.build_user end def create #... standard controller stuff end </code></pre> <p>views/members/new.html.erb</p> <pre><code>&lt;h2&gt;Sign up for new members!&lt;/h2&gt; &lt;%= simple_form_for @member do |f| %&gt; # user fields &lt;%= f.fields_for :user do |u| %&gt; &lt;%= u.input :email, :required =&gt; true, :autofocus =&gt; true %&gt; &lt;%= u.input :password, :required =&gt; true %&gt; &lt;%= u.input :password_confirmation, :required =&gt; true %&gt; &lt;% end %&gt; # member fields &lt;%= f.input :name %&gt; &lt;%= f.input :tel %&gt; &lt;%= f.input :city %&gt; &lt;%= f.button :submit, "Sign up" %&gt; &lt;% end %&gt; </code></pre> <p>I would like to point out that there is NO NEED to reach for nested_form gem; since the requirement is that User can only belong_to one type of Role. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload