How to name the model something like FileURL

I want to create a rail model, such as FileURL, without specifying file_u_r_l.rb. How can you do something like that? I understand that you can explicitly set the table name, but how to override the default file name to match class names?

Thanks Prateek

+4
source share
2 answers

You do not have to do anything. The Rails' .underscore method translates' FileURL 'to' file_url 'and will search for a file with the same base name in the download path.

If ActiveRecord does not guess the correct table name, use set_table_name:

class FileURL < ActiveRecord::Base set_table_name "file_urls" .. end 
+2
source

Ask yourself if this is really a requirement. In general, you better agree with the Ruby (and Rails) conventions, and not with them. Why not just name the model class FileUrl?

+2
source

All Articles