similar to: has_many how to not create object without child?

Displaying 20 results from an estimated 90000 matches similar to: "has_many how to not create object without child?"

2011 Sep 15
1
bypass defualt scope.
class Shop < ActiveRecord::Base has_many :documents, :dependent => :restrict end class Document < ActiveRecord::Base belongs_to :shop default_scope :order => ''updated_at DESC'' end in the Shop show view I have: - for document in @shop.documents %li(id="shop_documents")= link_to document.subject, shop_document_url(@shop, document) I want list
2011 Nov 12
3
complex form with dynamic fields.
I''ve seen http://railscasts.com/episodes/73-complex-forms-part-1, part2 and part3. It seems to be my case. I have: Company has_many :documents has_many :tenders, :through.......... and Document belongs_to :company Tender has_many :companies, :through.......... I want to insert documents and tenerds on company creation. If documents are more than one the user can click "add
2012 May 10
6
Is it suitable using STI?
I have problems on a simple design problem. I have many companies. Each company have one or more commercial activity. Activities types are: ecommerce, local unit, television, automatic vending machines, and so on. Company may have one or more ecommerce activity or one or more local unit activity, one ormore vending machines, etc. How can I model this scenario? Company has_many ecommerce has_many
2012 Jun 18
0
Creating an object with a nested has_many :through relationship
I have 3 models that define members, groups and the subscriptions: Member, Group, and GroupMember. class Member < ActiveRecord::Base > has_many :group_subscriptions, class_name: "GroupMember" > has_many :groups, through: :group_subscriptions > attr_accessible :email, :password > end > class Group < ActiveRecord::Base > has_many :member_subscriptions,
2011 Aug 17
1
has_many :through, collection<<(object) and duplicates.
Hi, I''m facing a strange behavior in Rails with the has_many association and the generated collection<<(object, ...) method that comes along. I''ve got an Object model and a Tag model, plus a taggings table to join the two together. On Object, I set these associations: has_many :taggings, :as => :taggable, :dependent => :destroy has_many :tags,
2011 Sep 01
0
do you think it's the best solution?
I have: class Shop < ActiveRecord::Base has_many :documents, :dependent => :restrict has_many :roles, :dependent => :restrict accepts_nested_attributes_for :documents accepts_nested_attributes_for :roles the shop _form is: = simple_form_for(@shop) do |shop_f| = render ''shared/error_messages'', :object => @shop = render :partial =>
2010 Aug 10
2
undefined method `has_many' for Object:Class +Savage Beast 2.3 plugin
Hi, i am using Savage Beast 2.3 plugin for the forum and i got and error undefined method `has_many'' for Object:Class C:/forum/vendor/plugins/savage-beast/lib/savage_beast/user_init.rb: 9:in `included'' C:/forum/vendor/plugins/savage-beast/lib/savage_beast/user_init.rb: 7:in `class_eval'' C:/forum/vendor/plugins/savage-beast/lib/savage_beast/user_init.rb: 7:in
2010 Oct 04
2
newbie q on activerecord - has_one and has_many on same table?
Hi I have a table where I need to identify one of the children as the "prime" child. So, its like: Parent has_many :Child has_one: Child :as :prime_child (?) or something like that? Do I put something like prime_child_id in the Parent table? Thanks. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this
2011 Jul 25
1
3 models in a form.
Hello, class Customer < ActiveRecord::Base has_many :deliveries class Delivery < ActiveRecord::Base has_many :delivery_items has_many :products, :through => :delivery_items belongs_to :customer class DeliveryItem < ActiveRecord::Base belongs_to :delivery belongs_to :product I create a new delivery for customer x: = simple_form_for @customer do |f| = f.simple_fields_for
2011 Feb 11
1
accept_nested_attributes, reject_if doesn't work.
class Post < ActiveRecord::Base validates :name, :presence => true validates :title, :presence => true, :length => { :minimum => 5 } has_many :comments, :dependent => :destroy has_many :tags accepts_nested_attributes_for :tags, :allow_destroy => :true, :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? or v.nil? } } end rails c
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:
2011 Jul 26
1
ActiveRecord has_many associations
Given the models Country, State, City and Person as follows. class Country < ActiveRecord::Base has_many :states end class State < ActiveRecord::Base belongs_to :country has_many :cities end class City < ActiveRecord::Base belongs_to :state has_many :people end class Person < ActiveRecord::Base belongs_to :city end Is there any way that doesn''t allow to delete
2011 Aug 04
1
Creating form for associated has_many model
This example shows how to create a form for an associated model ''Comment'', where ''Comment'' belongs_to ''Post'' and ''Post has_many ''Comments''. http://edgeguides.rubyonrails.org/getting_started.html#generating-a-controller How might I modify that to display all the comments in the form, and still have it call the
2011 Sep 04
2
has_many :through basic fubar
I''m trying to do, what seems like, a very basic join. However, the association just doesn''t seem to work. I''m sure it''s something very simple but I don''t know what. class Role < ActiveRecord::Base belongs_to :packages belongs_to :users end class Package < ActiveRecord::Base has_many :roles has_many :users, :through => :roles end
2010 Aug 19
1
has_many :through question
I am trying to create an association table using the ":through" option in "has_many" but not having success. I have created the necessary migrations of the association tables and run rake db:migrate I have the following model: class Group < ActiveRecord::Base has_many :users, :through => :group_user has_many :invites, :through => :group_invite, :class_name =>
2010 Mar 16
3
collection_select has_many
hi i have two models: GeoRegion & GeoRegionSub which have a has_many relation to each other. how can include the has_many relation in the collection_select helper? i want to have that dropdown where the parent is in black and the children indented. <%= collection_select :dl,:parent_id, GeoRegion.all.????, :id, :title %> thx -- You received this message because you are subscribed
2010 Jun 17
0
Edge Rails Nested has_many :through Association
So this functionality isn''t supported natively in Rails 3 (or any versions before that for that matter) But I had found a work around via this blog post: http://geoff.evason.name/2010/04/23/nested-has_many-through-in-rails-or-how-to-do-a-3-table-join/ This didn''t work on Rails 3 because it wasn''t able to properly build the query from the join with symbols. I was
2010 Jan 08
1
problem using build with has_many :through relationship
Hello all, I''m having problems creating a new record with has_many :through My application is quite complicated so I''ll try to explain it as easy as I can. I have a many to many relationship with Projects, IRBs and Reviews. Where reviews is the joined model. In the new project view, I have a link (add IRB). This will add an a list of IRBs to the new project form. I have visited
2010 May 31
2
has_many and has_and_belongs_to conflit
Hi, I have 2 models: User and Article. I have this relationship: * User has many articles (and Article belongs to user) * User has and belongs to many articles (and Article habtm users) But this is tricky because of: current_user.articles ...this can return articles thanks to *has_many* and *has_and_belongs_to* relations. So there''s a collision. How can I ask articles thanks
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,