Rails reserved names 1 points by ream88 12y ago ↗ HN It bothers me a lot each time I'm creating a Rails model which holds a reference to a file, because Rails does not allow the word "File". Any alternative solutions, what are the <i>big</i> Rails apps using?
[–] yxhuvud 12y ago ↗ File is the Ruby representation of the file class. It is a Very Bad Idea to reuse that name as is.Reusing names defined in Ruby stdlib classes is a bad idea. Name the model after what the file is used for, eg LockFile.Another option if you absolutely have to use that name, wrap it in a module, eg module Foo class File < ActiveRecord::Base end end And then always refer to it with the module prefix, ie Foo::File.
1 comment
[ 2.9 ms ] story [ 15.5 ms ] threadReusing names defined in Ruby stdlib classes is a bad idea. Name the model after what the file is used for, eg LockFile.
Another option if you absolutely have to use that name, wrap it in a module, eg
And then always refer to it with the module prefix, ie Foo::File.