Barney <bsperlin@...> writes:

> 
> Thanks Andrew, but I couldn't make the 'find' work on the
> 'PeopleSkill.where...' line.  When I used 'find' on the @people_skill
> line it came very close (since in the controller, listed above,
> people_skill was already choosing the field 'skill'), so when I used:
>  <%= @people_skill.find(@person.id)
> and skipped the next line listed above, the SQLException was
> SQLite3::SQLException: near ".": syntax error: SELECT  skill FROM
> "people_skills" WHERE "people_skills"."id" = 23 AND (:people_id =
> @person.id) LIMIT 1
> which is VERY close to what I want, except that I want
> "people_skills"."people_id"=23, not "people_skill"."id"=23.  I know
> that 'find' always looks for the 'id' so I've got to get a different
> variation.
> What changes should I make?
>      Thanks again,
>             Barney

What if we flip the logic?

Assuming your models look something like:

Person < ActiveRecord::Base
  has_and_belongs_to_many :skills
end

Skill < ActiveRecord::Base
  has_and_belongs_to_many :people
end

With the appropriate PeopleSkills join table in the database.

Then:

@person = Person.find(params[:id])
@people_skill = @person.skills

Or more easily:

def show
    @person = Person.find(params[:id])
end

and the view becomes:

<p>
  <b>Skills</b>
  <%= @people.skills >
</p>

or similar.





-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to