0

I'm making method that can used in Rspec test and Controllers. But i don't know where to store it.

Here are options that i have thought.

  1. application_helper -> but this file is used for method which used in applicaion controller.

  2. spec_helper.rb

  3. rails_helper.rb -> these two file is for rspec test

where should i store it?

I read this article but i'm not using models.

How to make a custom method that can be used anywhere in rails app

Now i had stored it at application_helper.rb, and call as

ApplicationController.helpers.custom_method

Is this right practice?

  • 1
    I usually place these shared helper methods in a file in `/lib` – Sergio Tulentsev Dec 13 '22 at 13:20
  • @SergioTulentsev thanks for your idea. There are two folders name as assets, tasks. which one should i use? – nicecoding521235 Dec 13 '22 at 13:22
  • Neither, create a new folder. – Sergio Tulentsev Dec 13 '22 at 13:23
  • `Is this right practice?` probally not. If its something generally reusable enough then `/lib` might be suitible but otherwise `but i'm not using models.` smells very fishy and leads to the immediate question why you are making an app in a MVC framework without models. – max Dec 13 '22 at 14:00
  • @max I've built such an app recently. It's not using models or views (in fact, it doesn't even load activerecord). It's an API wrapper over clickhouse, using its http interface. I'm using rails for the activesupport and other goodies (routing, familiar structure, gems, etc.). Works very well so far. – Sergio Tulentsev Dec 13 '22 at 14:07
  • @SergioTulentsev Of course there are valid cases where you might choose to not use models. I have also built applications which are basically just API wrappers but I still choose to use PORO models to encapsulate the data and the methods that act on it. Models do more then just persistence - they are the representation of the buisness logic of your application. – max Dec 13 '22 at 14:32
  • I use model in my rails app, but only my new method does not need model. – nicecoding521235 Dec 13 '22 at 15:33

0 Answers0