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

  • SEARCH
  • Home
  • 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 8664011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:08:13+00:00 2026-06-12T17:08:13+00:00

I’m currently working on my first rails project. I am trying to make a

  • 0

I’m currently working on my first rails project. I am trying to make a web app for uploading pics with friends. So on the form for creating an album, they should have a select field for which friends they want to share the album with. However, I am having trouble showing the names in the select field, and am getting an error

undefined method 'name' for nil:NilClass

even though my user database has the column “name” in it. Am I misunderstanding where “name” comes from? I thought attributes such as @users.name would mean go into the database and find me the name values of each user? Here are my files (let me know if you need any other files):

_form.html.erb (the one with the error)

<%= form_for([@user, @album], :remote => true, :html => { :id => "uploadform", :multipart => true }) do |f| %>
<div>
    <%= f.label :name %>
    <%= f.text_field :name %>


    <%= f.label :description %>
    <%= f.text_area :description %>

    <%= f.select :user, @users.name %>

    <%=f.label :avatar, "Upload" %>
    <%=f.file_field :avatar %>

    <br>

    <%=f.submit %>
</div>
<% end %>

album model

class Album < ActiveRecord::Base
  attr_accessible :avatar, :name
  has_and_belongs_to_many :users

  mount_uploader :avatar, AvatarUploader
end

user model

class User < ActiveRecord::Base

  has_secure_password
  attr_accessible :email, :name, :password, :password_confirmation
  validates_presence_of :password, :on => :create

  validates_format_of :name, :with => /[A-Za-z]+/, :on => :create
  validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create
  validates_length_of :password, :minimum => 5, :on => :create

  has_many :albums
  accepts_nested_attributes_for :albums

end

config/routes

Pholder::Application.routes.draw do
resources :users do
  resources :albums 
end

resources :albums do
  resources :pictures
end

albums controller

class AlbumsController < ApplicationController

    def index
      @albums = Albums.all

      respond_to do |format|
        format.html
        format.json { render json: @albums }
      end
    end

    def show
    end

    def update
    end

    def edit
    end

    def create
      @users = Users.all
      @user = User.find(params[:user_id])
      @album = @user.albums.build(params[:album])
      if @album.save
        flash[:success] = "Album created!"
      end 
    end

    def new
      @user = User.find(params[:user_id])
      @album = Album.new
    end

    def destroy
    end


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-06-12T17:08:15+00:00Added an answer on June 12, 2026 at 5:08 pm

    Pay close attention to the error, it can be confusing at first:

    undefined method 'name' for nil:NilClass
    

    It says “for nil:NilClass” not “user123:User” That means the object you are calling the #name method on is a nil object not a User object. The error is due to the @user instance variable not being set, so @user is nil instead of an actual user. So I’m guessing params[:user_id] is not being sent properly.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to select an H1 element which is the second-child in its group

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.