Reputation: 21566
I'm building what I thought was a fairly simple recipe app while learning RoR.
I've got a table for users, and a table for recipes, and a recipe_users table where a user is saving a list of recipes.
The error I'm getting from rails is "uninitialized constant User::RecipeUser"
My Models are as follows
class User < ActiveRecord::Base acts_as_authentic has_many :recipe_users has_many :recipes, :through = > :recipe_users end class Recipes < ActiveRecord::Base has_many :ingredients, :dependent => :destroy has_many :recipe_users has_many :users, :through => :recipe_users end class RecipeUsers < ActiveRecord::Base belongs_to :user belongs_to :recipe end
now in my users controller, I am attempting to call
@user = User.find(current_user.id) @userRecipes = @user.recipes.find()
looking at my mysql Show Tables, I get
recipe_users recipes schema_migrations user_sessions users
so as far as I can tell, I've got the naming conventions right.
Any suggestions as to why I'm getting this error?
Upvotes: 2
Views: 899
Reputation: 21566
It looks like this was an issue of naming conventions.
I deleted all references to recipe_users and recreated the table, model and controller as meals.
Not a great name, but it all came together without a hitch.
I've never liked the naming conventions that rails seems to expect I think in part due to the pluralization without actually informing the developer of what name rails may be expecting.
Upvotes: 1