I have two models:
Skillnames
and Skills
User
can create skillname
and skill
, in skills model
I have a reference "skill_id
" which means when I do Skillname.where(:id => @skill.skill_id)
it will give me back the name.
Now I'm super confused over something. I have created a search using PG_Search
and using associated_against
,Now I can search the Skill for the user using the skill_id (which is not so smart)
I was wondering if I can create something like this in the model of the skill:
virtual attribute:
def skillname=(skillname)
Skill.where(:skill_id => Skillname.where(:name => skillname).first.id)
end
update: adding the models:
class Skill < ActiveRecord::Base
include PgSearch
attr_accessible :user_id, :skill_id
belongs_to :user
end
class User < ActiveRecord::Base
include PgSearch
pg_search_scope :search, against: [:first_name, :last_name,:country],
:associated_against => {
:skills => :name,
}
end
class Skillname < ActiveRecord::Base
include PgSearch
belongs_to :user
attr_accessible :user_id, :description, :name
end