similar to: ActiveRecord find

Displaying 20 results from an estimated 30000 matches similar to: "ActiveRecord find"

2006 Mar 31
2
A.R. Associations problem
Hello, I''m learning A.R Associations by creating a simple forum that consists of 3 tables: ahuthors, topics and posts. This is the schema: class AddAuthorAndTopicAndPostTables < ActiveRecord::Migration def self.up create_table :authors do |t| t.column :username, :string t.column :email, :string t.column :created_on, :datetime end create_table
2006 Apr 11
4
Two versions of Rails on one PC
I want to have Rails 1.1 + Rails 1.0 on the same PC and be able to load my script with a different version each time. Is it possible? -- Posted via http://www.ruby-forum.com/.
2010 Jun 29
3
belongs_to. Association methods don't pass data to DB
Hi. I have a problem with the association methods which passed to a model through a belongs_to declaration. Here''s an illustration of the issue: GIVEN: # migration class CreateArticlesAndAuthorsTables < ActiveRecord::Migration   def self.up     create_table :articles do |t|       t.text     :title       t.integer :author_id     end     create_table :authors do |t|       t.text
2009 May 24
6
belongs_to not saving foreign key
Under Rails 2.3.2 using a completely brand new project, I have 2 models: class Author < ActiveRecord::Base # name:string end class Book < ActiveRecord::Base # title:string belongs_to :author # author_id end And a simple test where i create a Book with an Author using the belongs_to and then update the foreign key directly: require ''test_helper'' class BookTest
2006 Apr 06
5
Using helper method of another model
I have a template that belongs to a certain model (model A). I need to call a helper method of a different model (model B). Then I need the helper method of B to call a helper method of model C. I tried using "include" and "require" and using namespaces, but I got "undefined method". What is the way to do it? -- Posted via http://www.ruby-forum.com/.
2005 Dec 23
6
Save using Update
Hi, I want to update an existing row in table "items" where items.id == 10 I tried this: item = Item.new item.f1 = ... item.f2 = ... ... item.id = 10 item.save I got an error Duplicate entry ... for key 10 : INSERT INTO items ... How do I make item.save to use UPDATE instead of INSERT? -- Posted via http://www.ruby-forum.com/.
2006 Mar 19
3
Table belongs_to either of two other tables?
Suppose I have a site about books and authors, and users can leave comments on either a book or an author. I''d want to have a table called "comments", which could belong to either an author OR a book. In my structure I wouldn''t be sure whether to include an "author_id" or a "book_id", or both. What would be the best way to handle this
2011 Aug 11
17
f.collection_select: what are the parameters?
The rails docs are so horrible on the collection_select method. They need to show a *complete* form, and show two examples: one that calls f.collection_select(), and another that calls collection_select(), and explain the differences. Given this line: f.collection_select :topic, Topic.all, :id, :category What the !@#$!@#$ is :topic? -- Posted via http://www.ruby-forum.com/. -- You received
2006 Jun 13
6
Dead horse: validates_associated
Regarding validates_associated... Let''s say I have: article belongs_to author But for whatever reason, I want an article to also be written anonymously and therefore not require an author. Then I have: Article: belongs_to :author validates_associated :author But I DON''T have validates_presence_of. What I want to do is validate that an author is valid --if it is
2006 Jun 21
6
Sort table by child row property?
I''m building a simple forum system which features a topics and a posts table. The topic model has a has_many association with the post model, i.e.: class Topic < ActiveRecord::Base { has_many :posts } class Post < ActiveRecord:Base { belongs_to :topic, :dependent => true } Now, I wish to sort the topics by the created_at property of the last post, but I can''t
2006 May 20
3
Alphabetically sorted list pages + dynamic forms
Hey everyone, I''m new to RoR - how can I get my database content filtered by alphabet? Eg, on my php site now I use this format: http://www.scenepointblank.com/reviews/index.php?page=B How can I get this kind of functionality out of ruby? Also, how could I go about making a multiple select box of authors, then depending on how many you chose, the next page of the form displays a
2009 Mar 08
2
RESTful nested resources and polymorphism?
With ref to my previous post: http://www.ruby-forum.com/topic/180356 I am now able to access items from topics controller. However, now I need to add sub-item e.g.: An item itself could have many sub-items. So my items model is like: class Item < ActiveRecord::Base validates_uniqueness_of :title, :scope => [:topic_id] validates_presence_of :topic_id, :title, :owner, :position
2010 Jan 27
2
has_many, through with nested models?
First the data model: class Forum < ActiveRecord::Base has_many :topics, :dependent => :destroy, :order => ''created_at desc'' end class User < ActiveRecord::Base has_many :topics, :dependent => :destroy has_many :comments, :dependent => :destroy has_many :replies, :dependent => :destroy end class Topic < ActiveRecord::Base belongs_to
2006 Oct 19
3
joins and table names in ferret
I''m having trouble figuring out how to do Ferret queries across multiple tables as you would in a normal SQL call. For example, let''s say I have two ActiveRecord classes, Book, and Author, where Book has a ''description'' field and Author has a ''name'' field, and where Book has a belongs_to relationship with Author (Book belolngs to Author,
2006 Jan 08
22
Putting it all in one place with Schemas
I''m still relatively new to ROR, but I like what I see with the database-neutral approach of Schemas. In the spirit of keeping it simple and minimizing the number of files and location of information, does ActiveState currently allow me to go ahead and place other low level model information such as validation requirements and associations inside the schema rather than putting it in
2006 May 28
3
Working with topics and categories
Hello guys, I''m a newbie in RoR and I have a problem. My DB structure is ====================================== topics table : id(int,11) name(varchar,255) categories : id (int,11) topic_id(varchar,255) name(varchar,255) ====================================== --Models:-- class Topic < ActiveRecord::Base has_many :categories end class
2006 Jan 29
1
Accessing attributes
I have a name of an attribute and I need to get its value and set a new value for it: x1 = a.foo a.foo = x2 How do I do that if the name of the attribute ''foo'' is a var? I thought about doing this: attribute_name = ''foo'' x1 = a.attributes[attribute_name] a.attributes[attribute_name] = x2 but this is a bypass and I''m quite sure it would cause
2007 Jan 31
2
has_many :conditions
Is it possible to put conditions relative to the current instance in has_many''s :conditions? For example, in a forum app: class Post < ActiveRecord::Base belongs_to :topic has_many :self_and_descendants, :class_name => "Post", :order => "lft", :conditions => "topic_id = #{topic_id} AND (lft BETWEEN #{lft} AND #{rgt})" end With the
2006 Apr 25
6
Searching over multiple MySQL tables
I am racking my brain over this, probably because I only know very simple mysql functions. Basically I''ve got a few tables, ex: Albums (id,name,band_id); Bands (id,name,label_id), and Label (id,name) I want to search through both album.name, band.name, and label.name throwing all results into a variable, with no redundant info. I think what I need to be doing is setting up some
2006 Apr 03
2
Problems with STI in has_many/belongs_to in Rails 1.1
I have a problem that surfaced in my attempt to upgrade my application to Rails 1.1. We have a STI model on the "belongs_to" side of a has_many/belongs_to relationship. All my unit tests for this model pass, and the relationships all seem to work fine. But in my functional tests, I''m getting errors. I''ve traced it back into the call to the has_many