K
K
Kroid2015-01-05 18:06:25
Ruby on Rails
Kroid, 2015-01-05 18:06:25

Is it possible to move activerecord models to a separate gem?

The well-known rails provide the division of the application into, conditionally, 3 parts: model, view, controller. All logic related to data processing and interaction with the database should usually be kept in models.
Have you come across situations in which it would be desirable to separate a certain part (mainly models) from the rest of the application and include it as a gem? For example, if there is some independent part of the system that you would not like to mix with the rest of the application and develop separately. Maybe someone who wrote articles about this, throw links or share your experience.
update
After thinking it over again, I want to rephrase the question. Let's say I have some core functionality that I want to use in different applications. The problem is that this kernel uses activerecord models. What is the best way to arrange this so as not to copy model files from project to project each time?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Mikhail Osher, 2015-01-05
@miraage

Engines .
In fact, these are gems.

D
Dmitry, 2015-01-07
@Virviil

In fact, all active record models are a set of classes that are not related to the database, view-control, or anything else.
Make sure the model names are unique and wrap the gem with a simple require of each file in the gemname .rb file

A
Alexander Penshin, 2017-06-08
@maestro07

<option {% if state == "all" %}selected="selected"{% endif %} value="all">Все</option>
<option {% if state == "true" %}selected="selected"{% endif %} value="true">Оплачено</option>
<option {% if state == "false" %}selected="selected"{% endif %} value="false">Не оплачено</option>

E
Eugene, 2017-06-08
@immaculate

I would say that here it is not a specific template that needs to be changed, but the whole approach. Writing such HTML by hand is wrong. It's hard to write, hard to read, and even harder to modify.
It is correct to use django.forms.Formor django.forms.ModelFormand let it be displayed automatically by means of the same Django (form.as_p, form.as_ul) or django-crispy-forms.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question