Answer the question
In order to leave comments, you need to log in
How to pass parameter to Concern for model in ROR?
There is, for example, a certain function in concern that should take a parameter from the model in which it was connected, how best to do this?
For example:
concern:
module Fields
extend ActiveSupport::Concern
def set_fields
self.fields(variable_from_model).each do |f|
# some code
end
end
class User < ActiveRecord::Base
include ::Fields
variable_from_model= 'user'
end
Answer the question
In order to leave comments, you need to log in
Everything turned out to be easy!
module Fields
extend ActiveSupport::Concern
included do
class_attribute :entity
end
def set_fields
self.fields(self.class.entity).each do |f|
# some code
end
end
class User < ActiveRecord::Base
include ::Fields
self.entity = 1
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question