similar to: 2 models -> 1 model and class with array

Displaying 20 results from an estimated 50000 matches similar to: "2 models -> 1 model and class with array"

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
2012 May 28
4
How to load a selection list into the method new of a controller?
Hi friends! I''m relatively new with Rails and I''m struggling for a long time with this problem (it should have a pattern solution but until now I didn''t find it): I have the following models: Institution, City, State and Country. class Country < ActiveRecord::Base has_many :states has_many :cities, :through => :states end # == Schema Information # Table
2006 Dec 11
6
easy question, how would i search a grandparent???!
hi, i have this in my code Article.find_by_contents("#{searchstring} +city:#{passedincity}") well that returns to me only articles that belong to whatever the user selected in city. now is it possible to search the grandparent? for example class country has_many states class states has_many cities belongs_to country class city belongs_to states ...... i would like to search
2012 Mar 26
2
copy the columns based on the code
Hello, I have two different dataset, and wanted to join the two. For example I have a table of codes of cities, and other with with the codes of travels, [source for the destine]. what he wanted was to have a new data.frame with all the information city<-data.frame(city="Barcelona",cod=1) city<-rbind(city,data.frame(city="Madrid",cod=2))
2009 Jul 31
2
Undefined method updated? for <model object>
Hi, I have two model say- ZipCode < ActiveRecord::Base belongs_to :state_provinces end StateProvince < ActiveRecord::Base has_many :zip_codes end if I do @zip_code.update_atribute(:city, "My City") its giving Undefined method updated? for StateProvince if I remove belongs_to specifier in ZipCode class then it work fine. Any alternate solution?? Thanks -- Regards, Himanshu
2006 May 28
3
Validating Foreign Key
Howdy, I''m a Rails beginner working on my first significant project with RoR. I''m trying to figure out how to validate a foreign key (you know, make sure the row actually exists.) However, validates_associated doesn''t seem to be what I want to use, nor does it work... -- BEGIN -- class City < ActiveRecord::Base has_many :schools belongs_to :state
2009 Feb 23
2
geokit - using :through to connect models
hello.. i am currently trying to use :through to attach two of my models together using geokit. for some reason, i am running into a problem: ArgumentError: Unknown key(s): as i have two models, one that is geocoded, and one that belongs to that model. the models look like: ,----[ employer.rb ] | class Employer < ActiveRecord::Base | acts_as_mappable | before_validation_on_create
2006 Jul 29
0
displaying select value and debugging RoR application
Folks, I am running into the following problem. I have a company model that has_many addresses and address belongs_to company (it also belongs to a User model but I assume that is irrelevant to this issue). I am in the list_companies view of the company_controller. When the user selects a company from the drop down I dynamically update the cities dropdown for the cities that the selected company
2006 Apr 25
4
belongs_to :through
belongs_to :through Why is that not possible? We should have: Street belongs_to :city belongs_to :country, :through => :city -- Posted via http://www.ruby-forum.com/.
2010 Dec 14
5
Build associated model confusion
I''m new to Rails3, and I''m just trying to get one last thing to work before I call it a night. The situation is the following (please if the code is horrible, just let me know, still learning): I want to log a dive. I might have a new location on that dive at which point I have to create a new Location, and then create the dive. A dive has_one location. A location has_many
2009 Nov 06
0
Nested objects not propagating from view
I thought I had this fixed, but apparently not. It works okay from the console, but not from the view. I have the following: # partial schema create_table "users", :force => true do |t| t.string "login", :null => false t.string "first_name" t.string "last_name" t.string "email", :null => false
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 Jan 31
2
Relationship navigation issue
class Event < ActiveRecord::Base belongs_to :venue belongs_to :category end class Venue < ActiveRecord::Base belongs_to :city end class City < ActiveRecord::Base belongs_to :state end I want to retrieve all event records belonging to a state. Coming from hibernate background I tried something like this: def self.list_for_a_state(state_id) find_by_sql(["select e.*
2006 Jan 12
2
Can A Model Have Many belongs_to?
I am very new to Rails. After skimming through the documentation over the last several days, I''m struggling with the appropriate use of belongs_to. My main question is whether a model can have several belongs_to declarations. I have not seen any examples online show that usage. If it can, then I would like to know if it''s poor form or what the best practices are around
2012 Mar 20
2
Unique in DataFrame
Hello, I have little doubt, and I do not think that the way I solve the problem is the best way to do it. The following is a small dataset x<-data.frame(city="Barcelona",sales=253639) x<-rbind(x,data.frame(city="Madrid",sales=223455)) x<-rbind(x,data.frame(city="Lisbon",sales=273633)) x<-rbind(x,data.frame(city="Madrid",sales=266535))
2006 May 18
3
Model Madness: habtm vs through
This has me scratching my head: a Person has many Things a Person has many Collections a Collection has many Things ...Things in a Collection are ordered ...Things in a Collection can be related to (created by) any User ...a collection has additional attributes, such as a name etc I am confused about habtm in rails (especially when using acts_as_habtm_list) vs. going the :through route.
2006 Apr 20
3
has_many :through with has_many/has_many join models
It seems that using a join model that joins with two has_many''s will fail to generate proper SQL class StudentSemesterRecord < ActiveRecord::Base belongs_to :semester has_many :discipline_records, :through => :semester end class Semester < ActiveRecord::Base has_many :student_semester_records has_many :discipline_records end class DisciplineRecord <
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
2012 Jan 29
0
ActiveAdmin: Nested attributes not working for STI
HI All, I am having Model "Customer" using STI for sender and receiver, and i am unable to save the both sender and receiver by nested attribute. Below are my model and active admin resource codes, correct me if i am wrong nested attribute on concept. CUSTOMER MODEL: class Customer < ActiveRecord::Base belongs_to :sender, :class_name => "Customer" has_many
2013 Feb 26
0
Rendering nested resources
Hello, I have following models: States has_many Cities Cities has_many Streets Streets has_many Houses Houses has_many People In the routes.rb I have all these set as nested resources so I can view all the Cities of specific State as /states/1/cities, all the Streets of given City as /cities/15/streets, all the Streets of specific State as /states/27/streets, etc. Now in the houses#show