Barney <bsperlin@...> writes:
>
> 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
>
Again, the controller is returning a *relation*, rather than the actual
results. Try changing:
@people_skill = PeopleSkill.select('skill').where("{person_id => @person.id}")
to
@people_skill = PeopleSkill.select('skill').where("{person_id =>
@person.id}").all
Essentially this tells rails you are finished building the query and are
prepared for results - it will trigger a query against database.
I still can't help feeling you are experiencing these issues because you are
starting to swim upstream against the rails conventions. When things seem
difficult, there is usually some ruby voodoo missing. Knowing how to work
ruby and rails magic involves learning all the spells.
If you are still having difficulty, please post you model logic as well -
especially the relationships between the objects (belongs_to, has_many, etc)
--
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.