On 17 January 2012 16:55, Agis A. <[email protected]> wrote: > I've done it as you said, in the helper. So this is how it should be done? > Is there a general rule for deciding whether a function like this should go > into the controller or into the helper? > > My code in the helper: > >> def display_counter >> "You have visited this page " + pluralize(@times_visited, " time") if >> @times_visited > 5 >> end > > > and then calling that function in the view. Would it be better if this > wasn't a function but a simple variable like this? > @counter = "You have visited this page " + pluralize(@times_visited, " > time") if @times_visited > 5
I presume you mean to put this code in the controller. That is not desirable because then you are formatting data for display in the controller. The controller should make the data available to the view (@times_visited in this case) and then the view decides how to format it. So in answer to your question about a general rule the controller makes the raw data available, the view formats it. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

