It helped quite a bit actually. Thanks! On Feb 22, 10:20 pm, Andy Jeffries <andyjeffr...@gmail.com> wrote: > > This is probably an easy guess for some, but after searching the web > > for quite some time, I've concluded that I need help understanding > > this. > > > My case: > > > I'm creating an ad application where people can sell and buy items > > through their own ads. An ad belongs to one category, and therefore > > the question: When a user views all the current ads as a list > > (webisteurl/ads) - how do I make the categories show up next to that > > list like a clickable sorting menu? > > I'm not 100% sure which part you're stuck on. To get the association set up > you need to look in to ActiveRecord Relationships, in particular > has_and_belongs_to_many. > > class Advert < ActiveRecord::Base > has_and_belongs_to_many :categories > end > > Then in the view do something along the lines of: > > ...<%= @advert.content %>... > > <ul> > <% for category in @advert.categories %> > <li><%= link_to category.name, category_path(category) %></li> > <% end %> > </ul> > > You'd have a category controller; maybe using restful routes or a named > route such as: > > map.category "/category/:id", :controller => "categories", :action => "show" > > In that controller you'd do: > > @articles.find_by_category(params[:id]) > > And iterate over those articles in the view. > > Depending on where you were stuck, hopefully that's given you some hints to > get you moving. If not, post back with more details. > > Cheers, > > Andy
-- 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-t...@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.