Put them in a helper and include them in your controller(s).
If you want them to be available *everywhere*, write a new helper, say
GlobalHelper in a file called global_helper and in your
application_helper and application_controller say
class Application[Helper|Controller]
include GlobalHelper
...
end
BTW, a better way to implement this function is:
def empty_string? s
!(s && !s.empty?)
end
Better still, you can add an empty? method to NilClass, which negates
the need for the function in the first place:
class NilClass
def empty?
true
end
end
This means that you can now call empty? on a nil object or a string,
nil always returning true.
If you have many functions like that, you should really spend some
time reading the pickaxe book and the Ruby api docs. Also have a look
at the ruby facets library. I think you''ll find that a lot of what you
are trying to do is either already there or can be implemented in a
better way.
Max
On 8/23/06, rodrigo
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> I want to define some global functions, I mean, some functions that I
> can use from controllers or views, in example
>
> def empty_string?(cadena)
> if (cadena == nil) || (cadenal.length == 0)
> true
> else
> false
> end
> end
>
>
> where can I put this function? what if I have manny functions like this?
>
> Thank you
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---