Justin Meltzer
Justin Meltzer

Reputation: 13558

Why do I get this argument error?

I get this error:

ArgumentError in Videos#index

Showing /rubyprograms/dreamstill/app/views/layouts/application.html.erb where line #15 raised:

No association found for name `genre'. Has it been defined yet?

Line 15 is: <%= link_to "Profile", profile_path(current_user.profile) %>

Genre has a has_and_belongs_to_many association with Profile.

I have this in my routes:

resources :profiles
resources :genres

This is my genres controller(I'm trying to use this autocomplete field with a set of prepopulated genres:

respond_to :html, :json

def index
  respond_with(@genres = Genre.search(params[:q]))
end

And this is my Genre model:

has_and_belongs_to_many :videos
has_and_belongs_to_many :profiles

scope :search, lambda {|q| where("name LIKE ?', "%q%') }

This is in my application.js:

$("#genre_field").tokenInput(genres_path);

So why am I getting this error and how can I fix it?

Upvotes: 2

Views: 2677

Answers (1)

Jeffrey W.
Jeffrey W.

Reputation: 4169

As you have a has_and_belongs_to_many you should pluralize genre.

Upvotes: 4

Related Questions