ruby on rails 3 - How to do lookup table for roles -
ruby on rails 3 - How to do lookup table for roles -
i have table lists authors;
column :name, :string, column :role_id, :integer i have table roles
column :role_name, :string models:
author belongs_to :role role has_many :authors this seems strange. right author has 1 role , role belongs many authors?
now if have author can following;
@author.name , name.
how role_name
@author.role.role_name? thank in advance
your associations right - @ this explanation. also, answered own question, getting role name author can done
@author.role.role_name another alternative add together next line author model
delegate :role_name, :to => :role and able role name with
@author.role_name ruby-on-rails-3
Comments
Post a Comment