TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Rails reserved names

1 点作者 ream88超过 11 年前
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?

1 comment

yxhuvud超过 11 年前
File is the Ruby representation of the file class. It is a Very Bad Idea to reuse that name as is.<p>Reusing names defined in Ruby stdlib classes is a bad idea. Name the model after what the file is used for, eg LockFile.<p>Another option if you absolutely have to use that name, wrap it in a module, eg<p><pre><code> module Foo class File &lt; ActiveRecord::Base end end </code></pre> And then always refer to it with the module prefix, ie Foo::File.