How to name a model something like FileURL
I want to create a rails' model like FileURL without having to name the file file_u_r_l.rb. How does one go about doing something like this? I understand that you can set table name explicitly but how does one override the default filename to classname mapping?
开发者_C百科Thanks Prateek
You don't need to do anything. Rails' .underscore method translates 'FileURL' to 'file_url', and will look for a file with the same base name in the load path.
If ActiveRecord does not guess the correct table name, use set_table_name:
class FileURL < ActiveRecord::Base
set_table_name "file_urls"
..
end
Ask yourself whether this is really a requirement in the first place. In general, you're best off going with the Ruby (and Rails) conventions rather than fighting them. Why not just name the model class FileUrl?
精彩评论