Ruby on Rails Sunday, November 22, 2015

thanks tamara

 
As ever, Colin's advice is correct. Do work through a full tutorial,
maybe two or three times, even.

Notwithstanding that, there are a couple things you're trying to do
here.

1. defined scopes

the `.without_parents` would be a *scope* you have to define as a Class
Method on your Category model. It's essentially like so:

    class Category < ActiveRecord::Base
      # ...

      scope :without_parents, ->() { where( parent_id: 0 ) }

      # ...
    end

See http://guides.rubyonrails.org/active_record_querying.html#scopes


2. partials for collections


See http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials
subsection 3.4.5 Rendering Collections. When you have a collection of
categories, as you do with `@parent_categories`, you name the partial
`category.html.erb` (NOTE SINGULAR) and the variable available inside
that partial is also `category` (again singular) and it contains ONE
category from `@parent_categories` at a time.


--
Tamara Temple
tam...@gmail.com
http://www.tamouse.org

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/343b9008-aa1f-45f1-b87a-e8913402afc0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment