Answer the question
In order to leave comments, you need to log in
How to extend the has_and_belongs_to_many and has_many associations to assign a function to a single model object?
class Product < ActiveRecord::Base
has_and_belongs_to_many :specs do
def test
p 'Hello!'
end
end
end
Product.last.specs.test
will return 'Hello!' specs.each do |spec_one|
spec_one.test
end
to assign a function to a single Spec model object? (i.e. so that spec s [0].test outputs 'Hello!')
Answer the question
In order to leave comments, you need to log in
just add your method:
def test
p 'Hello!'
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question