Where to put code snippets in Rails?

Posted by Nik on Stack Overflow See other posts from Stack Overflow or by Nik
Published on 2010-05-21T05:00:46Z Indexed on 2010/05/21 5:10 UTC
Read the original article Hit count: 168

Filed under:
|

Hello all,

I have this code snippets that generates a signature for POSTs. The detail of it is not important, but what I want to know is: since it is not a model-related chunk of code, it really can be use anywhere: in controllers, in models, in view helpers; even in views. So I am unsure where and, even bigger of a problem, how to activate the use of it once I place it in some location.

Is it what those "require" statements are all about? That you can acquire some functionality through a "require" statement in the current file you are working on?

Just so that we have an example to talk about, say, I have a little snippet of code that does cubing:

def cube_it(num)
  num**3
end

I know that I will be using it in various places across the application, so where should I put it? and when I do need to use it, how can I "summon" it?

Thank You

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails