views:

25

answers:

2
+1  Q: 

Modeling Question

Hello,

I have the following two models:

class Project < ActiveRecord::Base
  has_many :photoalbums
end

class PhotoAlbum < ActiveRecord::Base
  belongs_to :space
end

routes.rb:

resources :projects do
  resources :photo_albums
end

What I'm trying to do in the Controller is get a list of all the project's photoalbums:

class PhotoAlbumsController < ApplicationController
  def index
    @project = Project.find(params[:project_id])
    @photoalbums = @project.photoalbums.all
  end
end

But I'm getting the following error?

uninitialized constant Project::Photoalbum
+1  A: 

Try has_many :photo_albums, and then @photo_albums = @project.photo_albums

theIV
thank you thank! the damn _ always screws me up.
Accept and rate the answer if it helped you.
nathanvda
+2  A: 

Replace all occurrences of photoalbum with photo_album.

Rails is smart and maps your photo_album to PhotoAlbum (note the two caps). It only capitalises at the beginning of a string or after an underscore. As you've seen, photoalbum corresponds to Photoalbum (one cap), which does not exist in your application.

molf