Rails: Where should I put this method? -


i have multiple models in application different types of content, , need whichever 1 published. @ moment, i'm using helper_method :latest_content in application controller.

is best place put method? if so, how should write rspec tests it?

sounds have common functionality across multiple models. rails has concerns allow that.

# app/models/concerns/searchable.rb module searchable   extend activesupport::concern    module classmethods     def last_content       # ... here whatever content of :last_content     end   end end    # app/models/model_x.rb class modelx < activerecord::base   include searchable   ... end  # app/models/model_y.rb class modely < activerecord::base   include searchable   ... end 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -