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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:08:16+00:00 2026-06-02T05:08:16+00:00

I have a Member model that belongs to User class Member < ActiveRecord::Base attr_accessible

  • 0

I have a Member model that belongs to User

class Member < ActiveRecord::Base

    attr_accessible :name
    belongs_to :user

end


class User < ActiveRecord::Base

    attr_accessible :name
    has_many :members, :dependent => :destroy

end

In my Members controller I have

class MembersController < ApplicationController

  def create
    @user = User.find(params[:user_id])
    @member  = @user.members.build(params[:member])
    if @member.save
      flash[:success] = "Member created!"
      redirect_to root_path
    else
      render 'pages/home'
    end
  end
end

In /app/views/users/show.html.erb I have

<%= form_for @member do |f| %>

  <div class="field">
    <%= f.text_area :name %>
  </div>
  <div class="actions">
    <%= f.submit "Submit" %>
  </div>
<% end %>

But I get the following error:
undefined method `model_name’ for NilClass:Class

Extracted source (around line #18):

15: 
16: <h1 class="member">What's up?</h1>
17: 
18: <%= form_for @member do |f| %>

My show action in the Users controller is

  def show
      @user = User.find(params[:id])
      @members = Member.new
      @title = @user.name
  end

Which also contains the ‘new’ method

I have tried changing :user_id to :id in the MembersController but this does not work either. What am I doing wrong here?

thanks in advance

  • 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-06-02T05:08:17+00:00Added an answer on June 2, 2026 at 5:08 am

    I needed to pass the @user.id as a hidden field in the form, for the association to work!

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

Sidebar

Related Questions

If I have the following models setup: class Member < ActiveRecord::Base has_many :children end
I have two models: class Member < ActiveRecord::Base has_many :member_tags end and class MemberTag
I have the following models class Project < ActiveRecord::Base has_many :project_members has_many :members, :through
I have a very simple issue: User model: class User < ActiveRecord::Base devise :database_authenticatable,
I have a model User, that has_many belongings (a belonging belongs_to a user). I
I have the following Model: class Group(models.Model): member = models.ManyToManyField(Player, through='GroupMember') name = models.CharField(max_length=20,
Model Member belongs_to Discipline , i.e. user can have a discipline but it is
I have a model called a Statement that belongs to a Member . Given
I have the model Member that contains all informations about the registered member on
I have a member function in a class that has a callback, but the

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.