I'm trying to use activemodel-associations to create a series of associations to build a query. However,
it appears that it's not building the expected methods, or at least those I expect..
The code is basically:
class YmmYear < ActiveRecord::Base
validates :year, presence: true
def name
self.year
end
end
class Ymm
include ActiveModel::Model
include ActiveModel::Associations
attr_accessor :ymm
belongs_to :ymm_year
def [](attr)
self.send(attr)
end
def []=(attr, value)
self.send("#{attr}=", value)
end
end
class Admin::YmmsController < ApplicationController
before_action :check_if_admin
def new
@ymm = Ymm.new
@ymm.ymm_year_id = 1126
end
end
The assignment to @ymm.ymm_year_id fails with NoMethod error.
undefined method `ymm_year_id=' for #<Ymm:0x9c549d8 @association_cache={}>
The methods to which @ymm responds that include "ymm_year" are:
I'm trying to use activemodel-associations to create a series of associations to build a query. However, it appears that it's not building the expected methods, or at least those I expect..
The code is basically:
The assignment to @ymm.ymm_year_id fails with NoMethod error.
The methods to which @ymm responds that include "ymm_year" are:
A classic ActiveRecord belongs_to assocation would create the accessor ymm_year_id, would it not? Or, am I misunderstanding this?
Thanks.