I have this
before_action method :
def convert_duration_reminder allowed_duration_units = %(hour day) if allowed_duration_units.include? params[:store][:store_setting_attributes][:reminder_unit] store_settings_params = params[:store][:store_setting_attributes] @duration_reminder = store_settings_params[:reminder_duration].to_i.send(store_settings_params[:reminder_unit]).to_i / 3600 else redirect_to store_settings_store_path(id: current_store.id) end end
I have a little bit of logic inside. The
@duration_reminder is after used in an
Does it belongs in the controller or the model? I think it belongs in the controller because I'm using params and I have a redirect and methods are short (except line length...) and it doesn't process any data in database.
In the book Rails 4 action, it says:
Models contain the domain logic of your application. This logic dictates how the records in your database are retrieved, validated, or manipulated. In Rails appli- cations, models define the code that interacts with the database’s tables to retrieve and set information in them. Domain logic also includes things such as validations or particular actions to be performed on the data.
Controllers interact with the models to gather information to send to the view. They’re the layer between the user and the database. They call methods on the model classes, which can return single objects representing rows in the data- base or collections (arrays) of these objects. Controllers then make these objects available to the view through instance variables. Controllers are also used for permission checking, such as ensuring that only users who have special permission to perform certain actions can perform those actions, and users without that permission can’t.