Displaying 20 results from an estimated 30000 matches similar to: "Sorting an array of models"
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?
2006 Apr 11
2
Finding items from two models - then merging them
I have a model, listings. Listings habtm categories and subcategories,
which are seperate models.
What I want to do is search categories for certain items, like so:
@categories = Category.find(:all, :conditions => ["name LIKE ?",
"#%{:search_string}%"
and subcategories for the same:
@subcategories = Subcategory.find(:all, :conditions => ["name LIKE ?",
2006 Apr 15
8
Inheritance in Rails - I need some help
I''ve got a model, "category" and another model "subcategory." Each
subcategory belongs_to a category, and a category has_many
subcategories.
What I need to do is set it up so that I can search Category and
Subcategory with one .find call. So:
Category.find(:all, <etc)
will find categories and subcategories.
Now, I believe this can be done by making
2006 Apr 22
9
one to many question
1. A category has parent categories.
2. A product is in many categories and a category has many products.
3. Products and category both have images in the same image table. ie. a
product and / or category could have multiple images.<=== my question is
related to this
So among other things I presume I have to do the following:
class Category < ActiveRecord:Base
#...
2006 Jan 10
5
Select Tag and Associations
Hi there,
I''ve been working on this for awhile and have finally decided to ask
for a little guidance.I have a slight problem trying to save a
selection.
I have two models:
A "Posting" has_many "Categories", and a "Category" belongs_to one
"Posting". With that said, in the posting model I have "has_many
:categories" and within the
2006 Apr 06
3
has_and_belongs_to_many find
Say I have a 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?
2006 Jun 18
6
integer array columns
Postgres database.
I have a categories table, with two columns id, and name.
I have a recipes table, with a category_ids column.
I want each recipe to belong to one or more category.
in recipe_controller.rb I have this:
def create
@recipe = Recipe.new( @params[''recipe''] )
@recipe.category_ids = @params[''recipe''][''category_ids''].map{
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 =>
2005 Jun 03
1
sorting on a habtm relationship
I have two tables ("products" and "categories") that have a
has_and_belongs_to_many relationship, and I need to be able to
arbitrarily sort products in the scope of a category using something
like acts_as_list. Problem is, since each product can belong to
multiple categories, it doesn''t work to use acts_as_list and have the
"position" field be in the
2006 Apr 20
8
Whats the best way to do this?
I have an archive that can have 0 or more extra files associated with
it.
I would like to be able to edit the associated files info on the same
page as the archive info.
Listing the extra files info to the edit form is simple enough, but How
do I form the text input fields for easy (or automatic) pick-up in the
update?
Or am I barking up the wrong tree here?
--
Posted via
2006 May 11
6
ActiveRecord associations
Can someone clarify this for me? Suppose I have two tables like:
class Company < ActiveRecord::Base
belongs_to :category
end
class Category < ActiveRecord::Base
has_many :companies
end
I understand that the belongs_to causes related companies to be read
from the db when I ask for a category. I suspect SQL something like
select * from categories, companies
where category.id
2005 Dec 16
3
Adding methods to models
All,
This is more of a theoretical question I suppose - I''m looking for what the
consensus is for the "correct" approach in Rails/MVC.
I have a standard security model where a User can have many Roles. There is
a User model, a Role model, and in the db, a linking table, etc. Each role
has a name as well as a category (say, name="waiter", category="restaurant
2006 Apr 15
7
New to rails - scaffold command , how to get related items?
Ahoy,
I was able to follow the tutorials and build a simple to-do list program
with Items and Categories and have the related tables link up w/ the
default "scaffold :Items" command plus custom defenitions.
Then I erased all of that and tried rebuilding the program using the
ruby script/generate scaffold Item (and category) command.
Now the templates look like
"
<% for
2006 Jun 29
4
Multiple belongs_to
Let''s say I have a catalog with hotels. Each hotel belongs to a
category (4-star, 5-star etc.) This is it''s official category.However,
there is also a category that users assign and a category that
"independent reviewers" assign. So I have this:
hotels {
id,
category_id,
reviewer_category,
user_category
}
categories {
id,
name
}
class Hotel <
2006 Apr 07
13
Pop up menus - any ideas?
I''ve got a menu in which I have all of my categories as links. Each
category also has subcategories. I want to set it up so when you mouse
over the category the subcategories will pop up (to the right of the
main list, but that''s just CSS). This is what I have so far:
<% for category in @categories %>
<a href="#"
2007 Nov 06
2
has_many :through problem
I''m building a simple support ticket system for use in our office. I''ve
got a model called Ticket and one called Category and I''m trying to set
it up so that I can add categories at will and assign many categories to
a single ticket.
I''m trying to use the has_many :through association to accomplish this,
but I''ve run into an issue.
Here''s
2006 May 25
5
Model Structure Advise
Hi,
I''m starting to build a simple (?!) FAQ system, and I''d like some
advice on setting up the model relationships.
I was going to go with a simple system of a Category table and a FAQ
table (holding questions and answers) - where one FAQ belongs to one
category.
That''s all nice - a simple has_many / belongs_to relationship. Then I
decided to add another level - Area.
2006 May 12
2
Has many through join table issues
I''m trying to wrap my caffeine soaked brain around has_many :through
following along at:
http://rails.techno-weenie.net/tip/2005/12/23/teaching_your_blog_model_new_tricks_with_has_many_through
I think my models are a little more complex than what fits this
narrative.
I have a directory of members, each member can belong to multiple
categories.
The category table references itself
2009 Jun 22
5
has_many through , or habtm , using form
i think there ara two ways of relate products and categories ,
basically i want to fix one product(e.g hp dv7....) to some categories
(notebook,17"notebooks...)
i made a table named categorization(incuding category_id,product_id
fields) then in models i write these codes below
class Product < ActiveRecord::Base
has_many :categories, :through => :categorizations
2006 Apr 21
6
How access to the tables whitout a model
i have a table called Products whit a model product, but in the view i
need show the category od the product, but whitout a model of
categories...
--
Posted via http://www.ruby-forum.com/.