What is the difference between Controller and Helper methods?

Asked

Viewed 491 times

3

Architectural and conceptual doubt:

I own a model Item who possessed attributes nome_ptbr and nome_en.

I did the following method:

def display_nome
  nome_ptbr || nome_en
end

Where should I put these methods, in the controller or in the helper? What’s the difference between one and the other?

1 answer

4


Helpers exist to be used by views.

If this method is only used by views, write it in the helper.

If it was intended to be used in the application, do it in the model if you need it on more than one controller, or do it on controller if it is specific to a controller.

Look at this SO-en question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.