Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3692506
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:16:13+00:00 2026-05-19T04:16:13+00:00

Here is my models: class User < ActiveRecord::Base has_one :worker, :class_name => ‘Worker’, :foreign_key

  • 0

Here is my models:

class User <  ActiveRecord::Base
  has_one :worker, :class_name => 'Worker', :foreign_key => :worker_id
  devise :database_authenticatable
  accepts_nested_attributes_for :worker
  attr_accessible  :worker_id, :email, :password, :password_confirmation, :remember_me, :workers_attributes, :worker_attributes, :name, :worker
end
class Worker < User
devise :database_authenticatable, :registerable
belongs_to :user
attr_accessible :name, :worker, :workers
end

I am trying to add the field name to the registretion form at
http://localhost:3000/workers/sign_up

The sign up form

<h2>Create Worker</h2>
<%= form_for resource, :as => resource_name, :url => registration_path(resource_name) do |f| %>

  <%= devise_error_messages! %>
 <table summary="Subject form fields">
      <tr>
        <th>Name:</th>
        <td><%= f.text_field :name %></td>
      </tr>
         <tr>
  <th><%= f.label :email %></th>
   <td><%= f.text_field :email %></td>
   </tr>
 <tr>
  <th><%= f.label :kodeord %></th>
  <td><%= f.password_field :password %></td>
  </tr>
  <tr>
  <th><%= f.label :bekraeft_kodeord %></th>
  <td><%= f.password_field :password_confirmation %></td>
  </tr>
   </table>
  <p><%= f.submit "Create Worker" %></p>
<% end %>
<%= render :partial => "devise/shared/links" %>

But i get a template error: Model Worker does not respond to name
And how do i create the association between User and Worker?

Best regards,
Rails beginner

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:16:13+00:00Added an answer on May 19, 2026 at 4:16 am

    I hope I understand well: I think you haven’t understand the STI concept yet.

    Let’s try to make it clearer.

    The classes you derive from an orinal model inherits everything from it. Your original model should look like this:

    class User <  ActiveRecord::Base
      devise :database_authenticatable
      attr_accessible :email, :password, :password_confirmation, :remember_me    
    end
    

    To really be a STI, you’ve to generate a migration to include “type” to your model. Simply type:

    rails g migration add_type_to_users type:string
    rake db:migrate
    

    Then set up you worker model which is really simple:

    class Worker < User
    end
    

    As you made, include in your routes.rb file:

    devise_for :users, :companies, :workers
    

    Now you’re done!

    Go to workers/sign_up, create an account and the go back to your terminal.

    From here, type rails c to start the console.

    Now try: User.all.last, you should see the account you just created with a ‘worker’ type

    And try: Worker.last, here again, you find the latest account created.

    Please remember: Rails is as great as simple 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have User and Album models with HABTM relationship class Album < ActiveRecord::Base has_and_belongs_to_many
I have a nested form with the following models: class Incident < ActiveRecord::Base has_many
Here's my code: class Publisher(models.Model): name = models.CharField( max_length = 200, unique = True,
I have the following models defined in my application User Profile Address Here is
Here are the domain model classes: public abstract class BaseClass { ... } public
Here's the deal: I got two db models, let's say ShoppingCart and Order .
I want to model messages between users, here is the requirement: User has received
Lets say I have two tables. class CreateUsers < ActiveRecord::Migration def self.up create_table :users
I'm learning Rails by writing simple TODO tasks aplication. Two models are: class List
Lets imagine I have the same database schema as here: http://www.databaseanswers.org/data_models/driving_school/index.htm If a customer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.