Note that there are some explanatory texts on larger screens.

plurals
  1. POundefined method `users' for nil:NilClass
    primarykey
    data
    text
    <p>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".</p> <p>My user controller.</p> <pre><code>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 </code></pre> <p>My user model is having.<br/> belongs_to :domain<br/> validates :domain_id, :presence => true<br/> <br/> and domain model is having.<br/> has_many :users<br/></p> <p>My new.html.erb form</p> <pre><code>&lt;%= form_for @user do |f| %&gt; &lt;%= f.label :first_name %&gt; &lt;%= f.text_field(:first_name, :size =&gt; 20) %&gt; &lt;%= f.label :last_name %&gt; &lt;%= f.text_field(:last_name, :size =&gt; 20) %&gt; &lt;%= f.label :email %&gt; &lt;%= f.text_field(:email, :size =&gt; 20) %&gt; &lt;%= f.label :password %&gt; &lt;%= f.password_field(:password, :size =&gt; 20) %&gt; &lt;%= f.label :password_confirmation, "Verify Password" %&gt; &lt;%= f.password_field(:password_confirmation, :size =&gt; 20) %&gt; &lt;%= f.submit "Create" %&gt; &lt;% end %&gt; </code></pre>
    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.
 

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