V
V
Voldemar Duletsky2014-06-30 11:26:38
Ruby on Rails
Voldemar Duletsky, 2014-06-30 11:26:38

When to move a method into a helper, and when into a module?

Do I understand correctly that the general methods for models are taken out in separate modules, for example,
models/user.rb

class User < ActiveRecord::Base
include Confirmable
...
end

lib/confirmable.rb
module Confirmable
  def some_method 
     ...
  end
end

While common methods for controllers should be placed in application_helper.rb or other helpers?
What is the best practice of taking out a duplicate when is optimal for models and controllers?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew Emelianenko, 2014-06-30
@YourWest

For models and controllers, there are so-called concerns (Concerns), I think this is exactly what you need: artemeff.com/2013/04/21/concerns-v-rails-4.html

D
Dmitry Snegirev, 2014-06-30
@Rikkit

View Helpers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question