mercredi 18 juillet 2018

How do I create migrations for model attributes in rails

I'm having difficulty with bulding attributes within my model. I keep seeing this error

NoMethodError: undefined method `users' for #<ActiveRecord::ConnectionAdapters::SQLite3::TableDefinition:0x00007f9d9ad9df98>

I need attributes that look like this:

#group.rb

class Spree::Group < ActiveRecord::Base
    has_many :users
end

#user_decorator.rb
Spree::User.class_eval do
  belongs_to :group, class_name: "Spree::Group"
end

For group.rb I ran

rails g model Spree::Group

and I got:

class Spree::Group < ApplicationRecord
  has_many :users
end

I'm confused on how to add 'has_many :users' without actually going into the model and inputting it there.

For the user_decorator I'm not sure what that migration would look like. Any help would be fantastic!

Aucun commentaire:

Enregistrer un commentaire