Displaying 20 results from an estimated 10000 matches similar to: "Forms with associations and collections"
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
2008 Feb 19
0
Issue with Observers and has_one association...
Hey Guys,
I''m getting a peculiar bug working with Observers and has_one
associations. When a has_one association is invoked by an Observer it
always returns null. I looked in the development.log file and the SQL
for the has_one association isn''t even being executed. On the other
hand, when I replace the has_one association with just a hand crafted
method, it does get called
2011 Mar 10
4
Multi-model forms
Hi guys, I''m new to ruby and rails and I''m working on multi model
forms, specifically 3. I''m using this http://guides.rubyonrails.org/getting_started.html
as a start, and its got a 2 Model example but I cant seem to get the
last one working.
These are my models:
Country name:string code:string (has_one :address)
Address address_line1:string
2006 Jan 30
1
Multiple associations between tables - do they ever work?
This is really bugging me. How can I get a second association to work
between 2 tables.
I have two models, User and Article. A user has many articles, and an
article belongs to one user. Then I have the "current article", which
is a the article that the user is currently viewing/editing. I want to
track/save this value, so they can come back to the same article if they
log out
2006 Apr 12
0
Looking for a simpler model using :through associations
Hi. I''m building a setup where I have users and groups, and a user can
have an optional title in a group (eg. "owner"). I''m doing this using
"has_many :through" associations, using a Role model object as the join hub:
class User < ActiveRecord::Base
has_many :roles, :dependent => :destroy
has_many :groups, :through => :roles
end
class
2007 Mar 01
0
association extensions - has_one
Hi,
I''m struggling with something that must be very common pattern, and
want to do it the correct rails/ruby way but am a bit dense !
I have users - an admin user, registered users and a guest user (using
ModelSecurity)
For many of linked associations I want the admin to be able to list or
edit all instances, the registered user only their own one and guest
none at all.
So somehow I
2006 Apr 20
4
Question about Associations
Hi all. Got a stupid-simple question about associations. I have two
models - school and course. There are a fixed number of schools (set
up in the migration). Each course is assigned a school and a school
will be associated with multiple courses...
How do I set up the associations? Do (can) I have School :has_one
:course and Course :has_many :schools?
Does the schools table then get a course_id
2008 Apr 21
0
Lost Polymorphic Associations in development environment causes delegate :blah, :to => to fail
Hi All
I have been struggling with this issue for a long time now. And before
I began to describe the problem its important to know that this
problem happens only in Development environment.
I am using Rails 2.0.2, here are my associations
class User
has_many :comments
has_one :profile, :as => :profileable
delegate :email, :to => :profile
end
First call to comment.user.email works
2006 Jan 06
0
bug rails activerecord association join
hi,
I found a bug in ActiveRecord association SQL INNER JOIN codes. in
has_many, has_one, habtm and belongs_to queries the foreign key is
determined from the table name of reflection and self. but that''s
worng because if you use a global prefix or suffix for your tables the
foreign keys will be in format of PREFIX_CLASSNAME_SUFFIX_id which is
wrong, because it breaks the advantage of
2006 Jan 06
6
HABTM problem not saving all associations
Hello all,
I have an Order object that has and belongs to many Products and has
and belongs to many Loan Types. This is so I can select multiples of
each in my order entry screen via checkbox groups.
I''m having some trouble with saving multiple HABTM associations for a
single model object; only the first HABTM association declared in the
model will save during the initial @order.save
2010 Nov 28
6
has_one accepts_nested_attributes_for fields_for NOT WORKING HELP
MODEL
class User < ActiveRecord::Base
has_one :address, :dependent => :destroy
accepts_nested_attributes_for :address
end
CONTROL
def new
@user = User.new
@user.build_address # Adicionei
...
VIEW partial _form
....
<% f.fields_for :address do |b| %> # Adicionei
<%= b.text_field :city_manual %> # Adicionei
<% end %>
2006 May 26
0
how to prevent child.save() when doing parent.save() in associations?
When using has_one or has_many associations, how do I prevent a call
to the parent''s save() method from calling the child''s save() method?
I seem to be stuck in an infinite loop due to the way I have my
associations setup :-(
thanks,
Tim
2006 Mar 08
2
Displaying related tables in forms.. probably an easy question!
Hey All,
I have two tables.. One belongs to another. Why can''t I reference
table1.table2.attribute?
Specifically, using scaffolding:
property.rb -
has_one :PropertyType
property_type.rb -
has_many :Properties
property_controller -
def list
@property_pages, @properties = paginate :properties, :per_page => 10
end
list.html:
1. <% for property in @properties %>
2.
2006 Jan 04
1
Multiple Associations With The Same Object
I have a Company object which has multiple Contacts
(has_many/belongs_to) I would like one of the contacts to be the
primary contact. What''s the best way to do this? Right now I have:
create table companies (
id int not null auto_increment,
name varchar(50) not null,
primary_id int null,
constraint fk_company_primary_contact foreign key (primary_id)
references contacts(id),
2006 Jul 03
0
Eager loading of ''is meant to be nil'' Associations
If I ''find'' using :include, and some included associations are null,
then looping through the array executing ''if obj[i].assoc'' accesses the
database for a second time (as obj.assoc is nil).
eg
Topic, has_many posts
Post has_one email
and
posts = Post.find(:all, :condition => ''posts.topic_id = 10'', :include =>
2007 May 14
0
building and saving has_many and has_one relations
Hi,
I am very confused about an aspect of has_one and has_many relations,
with regard to using the build method, and saving the belongs_to side.
It''s a somewhat long post. so please bear with me :)
First let''s consider the has_one scenario. Let''s say I have a student
who must own exactly one car:
class Student
has_one(:car)
end
class Car
belongs_to(:student)
2012 Dec 24
4
Bad idea to add/remove associations in after_find
I have 2 distinct types of users (artists and curators) in my system and
they currently share all associations (eg has_one :portfolio).
However, a curator shouldn''t have a portfolio so I would like to only
add that association when required. Obviously I could just return nil
for that method, but it doesn''t feel right having that there in the
first place.
What''s the best
2006 May 12
1
can I fake has_one :through?
I''m having a difficult time wrapping my head around a set of models
and their associations and seeing how they map into Rails. I''ll try
to lay out my problem using the has_many and belongs_to structures. I
have a RuleSpace, a Rule, and a Subject.
A RuleSpace has_many Rules
A RulesSpace has_many Subjects through Rules
A Rule belongs_to (many) RuleSpaces
A Rule has_many
2005 May 14
2
ActiveRecord::Associations::ClassMethods Documentation Issue
I''m curious, but isn''t this example in the documentation for
ActiveRecord::Associations::ClassMethods somewhat counter-intuitive? The SQL
DDL is correct for the way it''s used in the models. But isn''t it more
logical that an author would have many posts, rather than many authors
having one post?
From
2008 Nov 19
3
Overwriting / Decorating ActiveRecord association accessor
Hi,
I am trying to overwrite the accessor of a has_many association.
Basically my class looks like this:
class Person
has_many :emails
has_one :link, :class_name => ''PersonProxy''
def emails_with_link
link.emails + emails_without_link
end
alias_method_chain :emails, :link
end
Now that works fine if I only access the collection like
>>