On Sun, Feb 3, 2013 at 6:23 AM, Linus Pettersson
<
linus.pe...@gmail.com> wrote:
> If I have a method that is useful in both models and in views, where would
> be the appropriate place to put it?
# config/initializer/preload_helpers.rb
require "my_app/my_helper"
# lib/my_app/my_helper.rb ->
module MyHelper
module_function
def helper
puts "win"
end
end
# app/helpers/application_helpers.rb ->
class ApplicationHelpers
include MyHelper
end
# app/models/my_model.rb ->
class MyModel < ActiveRecord::Base
include Myhelper
end
> The method in question just takes two dates as strings, tries to parse them
> and returns all dates in the range between them. It also takes care of the
> issues when the dates are badly formatted etc etc..
>
> This method is being used in several models (so a simple class method in one
> model doesn't seem appropriate) and also in some view helpers.
>
> So, where does this method belong in rails?
Read Above.