I have two models : season and category. I want to display the category name in the season index view.
class Season < ActiveRecord::Base
attr_accessible :nb_down, :nb_up, :name, :category_id
has_one :category
accepts_nested_attributes_for :category
end
class Category < ActiveRecord::Base
attr_accessible :color, :name
belongs_to :season
end
In my season form, I add a category to season like this :
I want to display category name, and not id. I try to do "season.category.name" but no working. Where is my mistake please ?
Thanks :)
[EDIT] : i create a migration to add season_id in categories, and replaced I "has_one" by "belongs_to" in season class and it works : I can display the category name in the season index view.
Solution
create a migration
and add 'session_id' column in catogeries table
Run this command in project root directory in terminal