1

I created a scaffold for Etho, where I am attempting to have a User get 1 single "ethos" to edit. Ethos was working but on the User model it was only working with has_many :ethos

The user should only get 1 so I can create better associations. But now when I change in the model, it creates quite the spider effect that I can't track down.

User model:

class User < ActiveRecord::Base
  has_many :jobs
  has_one  :ethos #used to be has_many :ethos

On all the pages now I get uninitialized constant User::Ethos on EthosController#edit

Please help, how do I fix this?

tereško
  • 58,060
  • 25
  • 98
  • 150
Patrick A.
  • 103
  • 9

2 Answers2

0

Have you tried?

class User < ActiveRecord::Base
  has_many :jobs
  has_one  :etho 

has_one should be singular: http://guides.rubyonrails.org/association_basics.html#the-has_one-association

gabrielhilal
  • 10,660
  • 6
  • 54
  • 81
  • Right. But the second part describes what I can't figure out. has_one :etho gives undefined method `ethos' for # on EthosController#edit – Patrick A. Jul 09 '12 at 19:51
  • In your controller you need to change the `User.ethos` to `User.etho`. It must be singular as well. If it doesn't solve the problem please include the code for your controller. – gabrielhilal Jul 09 '12 at 19:57
  • Here is the public gist. It's working to where a user can now create an etho, but they should only have 1* and once it's created they should only be able to edit that 1* etho https://gist.github.com/3078792 – Patrick A. Jul 09 '12 at 20:47
  • as you have a `has_one` relationship, it won't allow you to create more than one `etho` for each `user`. What problem are you facing now? I sugest you to open a new question if you have a different problem... – gabrielhilal Jul 10 '12 at 08:49
0

You can continue to use the ethos pluralized name by explicitly specifying the class_name on the has_one association:

class User < ActiveRecord::Base
  has_many :jobs
  has_one  :ethos, class_name: 'Ethos' 

This answer provides additional details: https://stackoverflow.com/a/6604247/37966

Community
  • 1
  • 1
cweston
  • 11,297
  • 19
  • 82
  • 107