On Jan 17, 2012, at 11:55 AM, Agis A. 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

Try this:

        def display_counter(times, limit = 5)
          "You have visited this page #{pluralize(times,'time')}" if times > 
limit
        end

in the view:

        <%= display_counter @times_visited %>

> 
> 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

It depends on where you want to go to edit this code. It generates HTML, so it 
(fairly categorically) should not be in the controller. 

Walter

> 
> Thanks a bunch for your help so far!
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/rubyonrails-talk/-/pqZdc9v3pWgJ.
> 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.

-- 
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.

Reply via email to