activerecord - Rails Model needs to validate includes? class_name -


i have model called toolfilter column of 'tool_type'. string here refers class tool. put method in application_controller called tools_list gets descendants of tool.this works nicely in frontend, toolfilter complaining method tools_list.

class toolfilter < activerecord::base   validate :existence_of_tool   def existence_of_tool     unless tools_list.include? tool_type       errors.add(:tool_type, "invalid tool_type {{tool_type}}, use 'tools_list' see list of valid tool_object_types")     end   end  class applicationcontroller < actioncontroller::base   helper_method :tools_list   def tools_list     rails.application.eager_load!     tool.descendants   end 

it's bit strange tell model other classes in file system, need validate 1 of these. should put tools_list module , include in toolfilter? suggestions?

write include helper in model

applicationcontroller.helpers.tool_list 

though not recommend calling helper in model.

and checking tools classes damm bad idea.


Comments