Hi Andrew,
     Currently "show" works from the listings page but "new" and
"edit" don't. The current people_controller is:

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

    @people_skills = PeopleSkill.all

    @people_skill = PeopleSkill.select('skill').where("{person_id =>
@person.id}")

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @person, :xml => @peopleskill }
    end
  end

and the people_skills_controller.rb#show is:

 def show
    @people_skill = PeopleSkill.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @people_skill }
    end
  end

The people_controller.rb#edit, which doesn't work, is:

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

    @people_skills = PeopleSkill.all

    @people_skill = PeopleSkill.select('skill').where("{person_id =>
@person.id}")

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @person, :xml => @peopleskill }
    end
  end

and the people_skills_controller.rb#edit is:

 def edit
    @people_skill = PeopleSkill.select("skill").where("{person_id =>
@person.id}") #find(params[:person_id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @people_skill }
    end
  end

and these give an error in the \people_skills\_form.html.erb at the
first line:

%= form_for(@people_skill) do |f| %>
  <% if @people_skill.errors.any? %>

which is:
undefined method `model_name' for ActiveRecord::Relation:Class
and if I cut one @people_skill out of a controller I get:
undefined method `model_name' for NilClass:Class

and I take these both to mean that @people_skill doesn't exist.  Could
the 2 @people_skill instances be colliding?  Or the second shadowing
the first?

Any further help would be appreciated and I know you've put more into
this than you need to!
                Barney


On Jul 19, 8:17 pm, Andrew Skegg <[email protected]> wrote:
> 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