Ruby on Rails: models that do not have a table

What is the best way to create a model in Ruby on Rails that does not have a basic implementation for a database table? It is very common to write classes that perform behavior in a specific problem area, but can take advantage of some benefits that ActiveRecord has, such as validation.

Is it better to just create it as a module or helper? What is the best practice here?

+4
source share
1 answer

Check out the Ryan Bates screencast, which covers just that - the Heavenly Models.

http://railscasts.com/episodes/193-tableless-model

With this approach, your model will continue to be a subclass of ActiveRecord::Base , but it will define the columns manually, which will allow you to use ActiveRecord functions, such as checks and associations without a database.

+6
source

Source: https://habr.com/ru/post/1306314/


All Articles