Re: [Rails] Re: Printing nested data to screen

2011-07-21 Thread Curtis Schofield
> 
> I still can't help feeling you are experiencing these issues because you are 
> starting to swim upstream against the rails conventions. 

One of the unspoken conventions being violated is putting Queries in the 
Controller - :(


> If you are still having difficulty, please post you model logic as well - 
> especially the relationships between the objects (belongs_to, has_many, etc)


This is a really good suggestion. Spending time expressing the logic and what 
your purpose is
will increase the quality of help that you get - and likely reduce frustration.

-- 
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: Printing nested data to screen

2011-07-19 Thread Eric Hu
The original code didn't work because Barney was generating an ActiveRecord
Relation.  The .find almost worked, except he wanted to embed Ruby code in a
SQL statement.  This should do it:

PeopleSkill.where("people_id = #{@person.id}").find


In the future, I think something like Andrew's suggestion would be a lot
more readable and maintainable--I.E. using ActiveRecord to convert your
database information into objects, and looking for your information among
the objects instead of at the database level.


On Tue, Jul 19, 2011 at 5:17 PM, Andrew Skegg  wrote:

> Barney  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:
>
> 
>  Skills
>  <%= @people.skills >
> 
>
> 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 rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.