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 6362809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:57:25+00:00 2026-05-24T23:57:25+00:00

I am trying to create an application having domains and users, there are 3

  • 0

I am trying to create an application having domains and users, there are 3 types of users, super admin,domain admins and domain users.All the users(3 types) are in the users table and domains in domain table. At present there are domains and super admin. A super admin can login and create domains and domain users. The domains users should be related to a particular domain(i have a “domain_id” column in my ‘users’ table).Now when i am trying to create a user under a domain(after selecting a domain), i am getting this error “undefined method `users’ for nil:NilClass”.

My user controller.

def new
    @domain = Domain.find(params[:id])
    @user = User.new
    @title = "Sign up"
end

def create
    @user = @domain.users.build(params[:user])
    if @user.save
       flash[:success] = "Welcome to My Space!"
       redirect_to @user
    else
       @title = "Sign up"
       render 'new'
    end
end

My user model is having.
belongs_to :domain
validates :domain_id, :presence => true

and domain model is having.
has_many :users

My new.html.erb form

<%= form_for @user do |f| %>
  <%= f.label :first_name %>
  <%= f.text_field(:first_name, :size => 20) %>

  <%= f.label :last_name %>
  <%= f.text_field(:last_name, :size => 20) %>

  <%= f.label :email %>
  <%= f.text_field(:email, :size => 20) %>

  <%= f.label :password %>
  <%= f.password_field(:password, :size => 20) %>  

  <%= f.label :password_confirmation, "Verify Password" %>
  <%= f.password_field(:password_confirmation, :size => 20) %>

  <%= f.submit "Create" %>

<% end %>
  • 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-24T23:57:25+00:00Added an answer on May 24, 2026 at 11:57 pm

    Assuming @domain = Domain.find(params[:id]) in the new method does what it should do:

    def new
      @domain = Domain.find(params[:id])
      @user = @domain.users.build
      @title = "Sign up"
    end
    
    def create
      @user = User.new(params[:user])
      if @user.save
        flash[:success] = "Welcome to My Space!"
        redirect_to @user
      else
        @title = "Sign up"
        render 'new'
      end
    end
    

    And your view should look like this:

    <%= form_for @user do |f| %>
      <%= f.hidden_field :domain_id %>
    
      <%= f.label :first_name %>
      <%= f.text_field(:first_name, :size => 20) %>
    
      <%= f.label :last_name %>
      <%= f.text_field(:last_name, :size => 20) %>
    
      <%= f.label :email %>
      <%= f.text_field(:email, :size => 20) %>
    
      <%= f.label :password %>
      <%= f.password_field(:password, :size => 20) %>  
    
      <%= f.label :password_confirmation, "Verify Password" %>
      <%= f.password_field(:password_confirmation, :size => 20) %>
    
      <%= f.submit "Create" %>
    <% end %>
    

    Because of the hidden domain_id field in your form, the user will be assigned to the correct domain.

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

Sidebar

Related Questions

I'm trying to create an application that will let me execute a method specified
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
I am trying to create a WPF application that takes command line arguments. If
I'm trying to create a WPF application where I can drag an image around.
Trying to create a small monitor application that displays current internet usage as percentage
I'm trying to create a logger for a GWT application as an exercise to
i'm trying to create an application which connects to internet and consume web services
I'm trying to create my first Rails plugin and am having some troubles leveraging
I'm trying to create a Trial part of my cocoa application. I have the
I'm currently trying to created a custom ConfigurationSection for my application, however VS2008 is

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.