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

The Archive Base Latest Questions

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

Currently I’m making an app for users to create picture albums. The catch is

  • 0

Currently I’m making an app for users to create picture albums. The catch is that there can be multiple owners for each album, so in the form to create an album there is a check box portion where you highlight your friends names and “invite them” to be an owner. However, I am having a hard time getting it to work since it’s giving me an error in my AlbumsController#create. The error is :

undefined method 'user' for #<Album:0x007fcd9021dd00>

app/controllers/albums_controller.rb:43:in 'create'

Here’s my form

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

    <br>
    <label>Hosts</label>
    <% @user.friends.each do |friend| %>
    <%= friend.name %>
    <%= check_box_tag 'album[user_ids][]', friend.id, @album.users.include?(friend) %>
    <% end %>

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

    <br>

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

The checkboxes return an array of friend.id values that I want to invite to be owners for the album. The tricky part here is that I have a imaginary pending_album column in my join album_user model. Here’s what is sending me errors that I can’t figure out how to fix:

albums controller

def create
  @user = User.find(params[:user_id])
  @album = @user.albums.build(params[:album], :status => 'accepted')
  @friends = @user.friends.find(params[:album][:user_ids])
  for friend in @friends
    params[:album1] = {:user_id => friend.id, :album_id => @album.id, :status => 'pending'}
    AlbumUser.create(params[:album1])
  end
      #the next line is where the error occurs. why???
  if @user.save
    redirect_to user_album_path(@user, @album), notice: 'Album was successfully created.'
  else
    render action: "new"
  end
end

album model

class Album < ActiveRecord::Base
  attr_accessible :name, :description, :user_ids
  validates_presence_of :name

  validates :user, :uniqueness => true

  has_many :album_users
  has_many :users, :through => :album_users
  has_many :photos

end

user model

class User < ActiveRecord::Base

has_secure_password
attr_accessible :email, :name, :password, :password_confirmation, :profilepic
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
# validates :album, :uniqueness => true

has_many :album_users
has_many :albums, :through => :album_users, :conditions => "status = 'accepted'"
has_many :pending_albums, :through => :album_users, :source => :album, :conditions => "status = 'pending'"
accepts_nested_attributes_for :albums

has_many :friendships, :dependent => :destroy
has_many :friends, :through => :friendships, :conditions => "status = 'accepted'"
has_many :requested_friends, :through => :friendships, :source => :friend, :conditions => "status = 'requested'", :order => :created_at
has_many :pending_friends, :through => :friendships, :source => :friend, :conditions => "status = 'pending'", :order => :created_at

has_attached_file :profilepic

before_save { |user| user.email = email.downcase }

def name_with_initial
  "#{name}"
end

private

  def create_remember_token
    self.remember_token = SecureRandom.urlsafe_base64
  end

end

album_user join table model

class AlbumUser < ActiveRecord::Base
  attr_accessible :user_ids, :album_id, :status, :user_id
  belongs_to :album
  belongs_to :user
end

parameters (looks a little fishy… especially since album_id is nil):

{“utf8″=>”✓”,
“authenticity_token”=>”xkIi6+1vjEk4yQcFs9vI1uvI29+Gyuenyp71vhpX9Hw=”,
“album”=>{“name”=>”123123”,
“user_ids”=>[“27”,
“28”],
“description”=>”123123”},
“commit”=>”Create Album”,
“user_id”=>”29”,
“album1″=>{“user_id”=>28,
“album_id”=>nil,
“status”=>”pending”}}

I’m not too sure what I’m doing wrong. Can someone help please!!

  • 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-13T00:08:09+00:00Added an answer on June 13, 2026 at 12:08 am

    The error message is:

    undefined method 'user' for #<Album:0x007fcd9021dd00>
    

    All right, so something’s calling Album#user. Line 46 in the controller is @user.save, so how is user getting called?

    class Album < ActiveRecord::Base
      attr_accessible :name, :description, :user_ids
      validates_presence_of :name
    
      validates :user, :uniqueness => true    # <-- bam!
    
      has_many :album_users
      has_many :users, :through => :album_users
      has_many :photos
    end
    

    save triggers validations, including that line right there, which validates that user is unique. Since this is exploding, I’m guessing that user is a column that doesn’t exist, either because a) it’s not defined in a migration or b) you didn’t run the migration.

    (As an aside, I’m rather confused as to why you would have a unique user attribute on Album, an AlbumUser model with both user_id and user_ids, and a User model. Maybe it makes sense, but I think it’s more likely that it all needs a cleanup.)

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

Sidebar

Related Questions

currently, I`m implementing a map App with Mono4Droid and there I`m using a WebView
Currently, my MVC 3 app has a dependency on a static class that is
Currently, my ListViews look like this: How can I achieve that Windows 7 native
Currently, I am writing a MiddleWare application that synchronizes information between and accounting application
Currently working with converting SQLException error messages into messages that are more useful for
Currently, Enum.Parse supports only the comma as the value separator, so that MemberOne,MemberThree will
Currently createPopup() is only supported in IE (See http://help.dottoro.com/ljsxcrhv.php ). Is there a universal
Currently, I have a GWT based application /app.htm It displays an openId login button
Currently I have a UITableview, I have enough data that cannot be shown entirely
Currently I am debugging the signing of an Android app. And this would be

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.