Dr. Chocolate
Dr. Chocolate

Reputation: 2165

Where to create a basic class in rails?

I just want to create a wrapper/decorator class that I pass a model into and get a class with formatted output fields back.

Where is the best place for that to go?

I have it in the models folder but my spidey sense is tingling to look more into it.

Upvotes: 0

Views: 41

Answers (3)

CDub
CDub

Reputation: 13344

These days, the best practice I have seen is to create a directory under app/ which follows the name of your project. Generally this is the "domain" directory for classes which are specific to your app.

For example, if your project name is "blog", you'd create a directory called app/blog. Then, you can create subdirectories and namespace classes appropriately for organization.

Further example: To create a PostDecorator, you could have:

app/blog/decorators/post_decorator.rb

Which would look like:

module Blog
  module Decorators
    class PostDecorator

      #code

    end
  end
end

Upvotes: 0

djaszczurowski
djaszczurowski

Reputation: 4515

you say formatted. IMHO YourModelPresenter is a good name (more descriptive I think than Decorator), and then I would put it in app/presenters

Upvotes: 2

apneadiving
apneadiving

Reputation: 115511

Convention for decorators would be /app/decorators

This is basically the case for draper classes

Upvotes: 3

Related Questions