I have two classes:
class User < ActiveRecord::Base
:has_one :foo
end
class Foo < ActiveRecord::Base
:belongs_to :user
end
The Foo is optional.
I created the following routing:
resources :users do
resources :foo
end
Which results in the following routes:
GET /users/:user_id/foo(.:format) {:controller=>"foo...
I have two classes Message and User. Message has sender_id and recipient_id both foreign keys for User. How to build relationship where I'll be able to get user for both sender and recipient, like @message.sender.name and @message.recipient.name
I tried to do it by this way:
class Message < ActiveRecord::Base
belongs_to :sender, :...
Good morning all,
I've got an association that I'm working on, and for some reason, I can't get it to save changes to the object in question when I'm debugging it in IRB. I was wondering if anyone could point out my problem.
Here is the association:
class User < ActiveRecord::Base
has_and_belongs_to_many :affiliates
has_one :mana...
I have an application which has the following characteristics
There are Clubs
Each Club has Teams
Each Team has Players
I have a users table. The user table basically contains the username and password for the club manager, team manager and the player to login to the system.
How should I structure the models and the tables?
I plan...
For example, in
class Student < ActiveRecord::Base
has_many :awards
end
class Awards < ActiveRecord::Base
belongs_to :student
end
the above should be the correct usage, but what if we use
class Student < ActiveRecord::Base
has_many :awards
end
class Awards < ActiveRecord::Base
has_one :student
end
doesn't the above also m...
I want to be able to change value for the :status_contact for the model Contact (has_one :status_contact
Here is the snippet with the link_to_remote:
<%= link_to_remote "Responded - Positive",
:url => contacts_url(@contact, :status => 'positive response'),
:update => "status" %>
<span id="status"></s...
I have an application where my users can have a set of preferences. Both are stored as ActiveRecord-models as follows:
class User < AR::Base
has_one :preference_set
end
class PreferenceSet < AR::Base
belongs_to :user
end
I can now access the preferences of a user:
@u = User.first
@u.preference_set => #<PreferenceSet...>
@u.pre...