Model inside subfolder in the model folder

I am using Ruby on Rails 2.3.8 and I would like to know how to organize models in subfolders so that Ruby can recognize them.

+3
source share
2 answers

As I understand it, you need to simulate your models so that they can be loaded.

use generator:

> ./script/generate model Customer::Address

will create a model in app/models/customer/address.rb

class Customer::Address

end

It will load recursively, but in order for the rails to find it, it is necessary that the namespace matches the outline.

, ( , 2.3.5 , ). customer_addresses, - addresses. , set_table_name 'customers_addresses' , .

+8

Rails /app/models ( Ruby 2.0+). : , , ..

+3

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


All Articles