I have a table called people_skills linked to a people table by a FK
named people_id. Trying to get the people_skills fields printed on a
“Show” screen has never given me what I wanted (the field value)
without resorting to a helper which forms an input box. The people
table’s values are printed but the results of the people_skills are
either non-existent or strange (e.g. #<ActiveRecord::Relation:
0x1d12778>).
This is the controller code (people_controller.rb):
def show
@person = Person.find(params[:id])
@people_skill = PeopleSkill.select('skill').where(":people_id =
@person.id")
show_skill = @people_skill.build.skill
yrs_exp = @people_skill.build.years_of_experience
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @person, :xml => @peopleskill }
end
end
and this is the show.html.erb:
Skill <%= @people_skill.build.skill %> <%= PeopleSkill.where("people_id = @person.id")%>
which produced the strange #<ActiveRecord… output above. Other
guesses have either given me errors or no output at all, so please
tell me the right way to do this.
Barney