search for: find_by_category

Displaying 5 results from an estimated 5 matches for "find_by_category".

2006 Apr 13
2
Automatic finder
It looks rails automatically creates a "finder" method on models that have a "belongs_to". So I tried this in the console: c = Category.find(2) chunks = Chunk.find_by_category(c) chunks is always returned as an empty array. When I know have some chunks with a category_id of 2. Should the find_by_category do what I think it should be doing or am I completely off base? thanks, cott. -------------------------------------------------------------------------------------...
2005 Dec 16
3
Adding methods to models
...model, and in the db, a linking table, etc. Each role has a name as well as a category (say, name="waiter", category="restaurant worker", for example). I can check to see of a user has a particular role by doing something along the lines of @session[:user].roles.include?(Role.find_by_category("restaurant worker")) There is probably a shorter way of doing this, but the point is this: Would it be "correct" in the Rails/MVC world to add a method to the User model so that you could do @session[:user].has_role_category?("restaurant worker") (with a better nam...
2006 Apr 06
3
has_and_belongs_to_many find
...post model that has_and_belongs_to_many :categories, and a category model that has_and_belongs_to_many :posts. So I have a categories_posts table to do the join. That''s all find and dandy. However I want to be able to find all the posts that belong to a specific category. I tried Post.find_by_category(:id) but that doesn''t work. Does anyone have any insight? Thanks in advance. -- Posted via http://www.ruby-forum.com/.
2006 Apr 13
3
Sorting an array of models
I have a model, listing, which belongs_to one or more categories. I need the user to be able to search for categories by name (which I can do) and have it return all the listings that belong to those categories. This I can do. However, what I need to do is take that list of listings and sort them by one of their fields. This is a bit more complicated, without needing to sort I could just do:
2006 May 01
3
Routing requests without ID parameter
Hi there, This seems to be obvious but after reading a few times the section in the Agile Wb Dev with Rails I''m still strugling. I have a table with categories names which I want to display in the url instead of their id. So far I managed to get both in the url by adding: map.connect ''/:id/:category/'', :controller => "site", :action =>