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 autocomp开发者_如何学编程lete 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?
As you have a has_and_belongs_to_many
you should pluralize genre
.
精彩评论