Questions tagged [belongs-to]

This is a master-detail relationship where one item "belongs_to" another and has a foreign key to maintain the relationship.

A master record has many detail records.
For example if we have buildings and rooms we can say that one building has_many rooms.
In a database, with tables/models, this relationship implies that rooms will have a foreign key for which building they belong to and thus the relationship will be belongs_to.

756 questions
-1
votes
3 answers

Overriding object in belongs_to relation

I have such models: class User belongs_to :authenticity end class Authenticity has_one :user end now I create authenticity for user: u = User.first; u.authenticity = Authenticity.create and now I assign new authenticity: u.authenticity =…
ciembor
  • 7,189
  • 13
  • 59
  • 100
-1
votes
1 answer

Devise: NameError (undefined local variable or method `user_id=') in controller when using `current_user`

I'm using Devise in my Rails app. A Project belongs to a (devise) User. (Relevant models are below.) When the create action is called in ProjectsController, however, the following error is shown in the server logs: NameError (undefined local…
bitfizzy
  • 157
  • 1
  • 1
  • 8
-1
votes
2 answers

Rails - how to make association between these models (not based on "id", but on "email")

I have these models that obviously have more attributes, but for simplicity I kept them just like this: class User < ActiveRecord::Base has_many :subs, :foreign_key => :email, :class_name => "subs" end class Subscription < ActiveRecord::Base …
user984621
  • 46,344
  • 73
  • 224
  • 412
-1
votes
1 answer

Nested form can't mass assign, create action

I had to add the pen attributes to the paper model to stop the error "can't mass assign :pen", even thought I had the attr_accessible for pen_attributes. Now, I'm getting a "unknown attribute: pen" error. It's pointing me to the second line of the…
-2
votes
1 answer

Rails has_one belongs_to display field in index?

I have two models : season and category. I want to display the category name in the season index view. class Season < ActiveRecord::Base attr_accessible :nb_down, :nb_up, :name, :category_id has_one :category accepts_nested_attributes_for…
John
  • 198
  • 2
  • 10
-2
votes
1 answer

Traversing through pixels

Say that we have the following part of an algorithm, provided that I want to implement it in matlab: k = 0; while k
Simplicity
  • 47,404
  • 98
  • 256
  • 385
1 2 3
50
51