similar to: find() and has_many

Displaying 20 results from an estimated 70000 matches similar to: "find() and has_many"

2007 Jul 29
1
Curious why this doesn't work. (has_many, belongs_to)
Two Models. class Gm < ActiveRecord::Base belongs_to :pool # mode code here. end class Pool < ActiveRecord::Base has_many :gms # mode code here. end Testing code through the console. >> gm_list.each{ | gm | puts " GM name: #{ gm.user_name } belongs to Pool: #{ gm.pool.pool_name } " }; nil GM name: John belongs to Pool: RHP 07-08 Season - Career League GM name:
2007 Apr 04
4
Order a find using a has_many association
I''m trying to order a find through a has_many association. I have a model called SalesOrder. Each sales order has things like amount, description, etc. I use the following to get the Sales Orders: @sales_orders = SalesOrder.find(:all) And I display them with: <td><%= link_to sales_order.id.to_s, :action => ''show'', :id => sales_order.id
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
2011 Mar 01
6
render :collection calling partial with phantom object?
I have two models with a straightforward has_many / belongs_to relationship: class Premise < ActiveRecord::Base has_many :metered_services, :dependent => :destroy ... end class MeteredService < ActiveRecord::Base belongs_to :premise ... end and nested routes to match: Demo::Application.routes.draw do devise_for :users resources :premises do resources :metered_services
2006 Jun 13
0
question about saving associations when using has_many :through
I''ve got a User model and a Book model. A user is required to submit books each month to be reviewed by other users. I have the following relationships defined: # the join model book_review.rb belongs_to :user belongs_to :book end book.rb # each book is reviewed by many users. This allows us to get the BookReview # objects associated with this book has_many :book_reviews,
2006 Jan 05
1
recipes/categories to books/authors but listing doesn''t work
People, I have gone through the cookbook example: http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html?page=1 and everything worked fine an a FC4/Postgres setup. I then tried to reproduce this success with something that would be useful to me - a library db using books & authors tables. The author list works but NOT the book list (unless I take line #17 out). I get this message:
2006 Jan 25
1
url_for_file_column in parent model''s view
Hi All, I am using the file_column plugin to upload images. The model that I am using is simply called images (id, name, caption - name being the "file" column) and it belongs_to a parent model called books which has_many images. I was able to figure out how to enter the images into the correct model when updating of form of the parent model (books). Now I need to figure out
2008 Feb 22
4
has_many and belongs_to in rails 2.0.2 (child.Parent) is not working
Hi All I have 2 models working well in rails 1.2.6 : class TypeService < ActiveRecord::Base has_many :Services end class Service < ActiveRecord::Base belongs_to :TypeService end I was able to get the name of the service with Rails 1.2.3: s = Service.find(1) name_type_service = s.TypeService.name <<-- Now with rails 2.0.2 that doesn''t work With rails 2.0.2 s
2006 Aug 16
0
Testing has_many, :through relationships
Hi All, This is my first post on this list. I''m a developer working on the Central Coast of NSW, Australia and came across RSpec via Lachie who demoed RSpec on Rails at a Sydney rails user group meeting a couple of months ago. I''m loving the expressiveness of RSpec and can''t really see myself going back to Test::Unit. I''ve come across one oddity though. I
2007 May 28
2
Rails, respond_to? over anonymous module (extend has_many).
Hello List, I''m trying to generate examples for some list-helpers I have coded which use in my projects. Basically, the Playlist class uses one anonymous module in has_many that acts as helper between acts_as_list and my desired API: class Playlist < ActiveRecord::Base # associations go here has_many :playlist_items, :order => :position, :dependent => :destroy has_many
2006 Feb 23
3
has_many reference
I am trying to do something right from Agile Web Dev with Rails book and it does not work. I must be missing something obvious. I have a one-to-many relationship: class Draft < ActiveRecord::Base has_many :endorsees end class Endorsees < ActiveRecord:: Base belongs_to :draft end >From my reading, methinks I should be able to say: d = Draft.new d.endorsees << Endorsee.new
2006 Apr 05
3
CRUD pattern for has_many relationships (forms containing collections)?
Hello folks! Beare with me for a second, while I explain my problem. Assuming we have the trivial model of class Author has_many :books end class Book end How do people go about creating the authors/edit and authors/new views if you want to be able to add and remove arbitrary amount of Books at Author creation and edit time? What I mean by this is that I go to
2009 Sep 28
7
Basic Rails problem with has_many nil values and permalinks
Hi, I have a model property with has_many. I find the property and then I need to find the name of the building or the neighborhood that the property belongs to. The property is not always assigned a building or neighborhood. This becomes a problem when createing permalinks with permalink_fu. has_permalink [:neighborhood_name, :building_name, :address] The neighborhood name and building name
2010 Feb 06
1
accepts_nested_attributes_for with has_many => :through
I have two models, links and tags, associated through a 3rd model, link_tags. I added the following to my link model, has_many :tags, :through => :link_tags has_many :link_tags accepts_nested_attributes_for :tags, :allow_destroy => :false, :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } } and put this in a partial called by the new and edit forms for links,
2010 Jun 03
2
creating fixtures for has_many :through
I''m stymied at how to create a fixture that establishes a has_many :through relationship. I''ve watched the railscast at: http://media.railscasts.com/videos/081_fixtures_in_rails_2.mov ... but that''s for HABTM relationships. I''ve read: http://www.ruby-forum.com/topic/145676 but that ultimately doesn''t answer any question. So with no further ado:
2009 Aug 17
1
Problem with setter override on ActiveRecord
(This message was originally written on StackOverflow -- the formatting is much prettier there -- http://stackoverflow.com/questions/1283046/problem-with-setter-override-on-activerecord) This is not exactly a question, it''s rather a report on how I solved an issue with write_attribute when the attribute is an object, on Rails'' Active Record. I hope this can be useful to others
2006 Sep 08
1
has_many relationship extensions and scoping rules
Hi all ! Is this supposed to work ? class Email < ActiveRecord::Base has_many :to, :class_name => 'Recipient', :conditions => "recipients.source = 'to'" do def create!(*args) with_scope(:create => {:source => 'to'}) do super end end def build(*args) with_scope(:create => {:source => 'to'}) do
2007 May 22
3
can I use acts_as_list with a has_many :through association
I''d like to be able to use a has_many :through association and treat the associations as a list but I''m getting this error when I try an use an acts_as_list method: NoMethodError: undefined method `move_to_bottom'' I''m using edge rails r6786. Here are my domain rules: Activities are things students can do. Units consists of a sequenced list of
2006 Mar 20
11
has_many brings back ''uninitialized constant''
hello. first things first - I am new to ruby on rails (ruby, too), so I''m figuring this is just a basic newbie error. I''m creating a basic photography website. And I have two tables with a relationship: photos: - id (set up as PK) - title - shutter - aperture - date - the_order ...etc photo_comments: - id (set up as a PK) - photos_id (set up as a FK) - author - date -
2010 Apr 02
6
App_Controller and partial issues with has_many through
I have a User model, a Post model, and an Interest model: User has_many posts through interests User has_many interests, dependent destroy Post has_many users through interests has_many interests, dependent destroy Post has_many interests Interest belongs to Post Interest belongs to User Application_Controller is as follows: class ApplicationController < ActionController::Base before_filter