Rails 4 model subfolder -


i'm created model in app/models/request/book folder book::request::status.table_name returns table name "statuses" ("book_request_statuses" - right table name). how can correct table name?

model location

 model/   book/     request/       status.rb 

model/book/request/status.rb

class book::request::status < activerecord::base ... end 

config/application.rb

config.autoload_paths += dir[rails.root.join('app', 'models', '**', '*.rb')] 

if set self.table_name = "book_request_statuses" model work correctly (in model), it's not way :).

sorry english not good

1) create module in app/models/book.rb these lines.

module book   def self.table_name_prefix     'book_'   end end 

2) create module in app/models/book/request.rb

module request   def self.table_name_prefix     'request_'   end end 

3) put status model inside app/models/book/request/ directory.

4) keep other files intact.

i hope works you.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -