rake db:populate 在 Rails 3 中工作吗?
我的 populate.rake 文件遇到了巨大的问题 - 从 Rails 2.3.5 安装导入现有文件后,Rails 3 不想与它有任何关系。我的控制台中出现了数十个(如果不是数百个)错误,其中许多是简单的语句,有些甚至在一串明文的中间。
Rails 3 填充的语法是否已更改,或者我是否需要为其安装 gem/插件?
非常感谢。
I'm having huge problems with my populate.rake file - after importing my existing file from my Rails 2.3.5 installation, Rails 3 wants nothing to do with it. I'm getting tens (if not hundreds) of errors in my console, many of them for simple statements, and some even in the middle of a string of plaintext.
Has the syntax changed for Rails 3 populate or, perhaps do I need to install a gem/plugin for it?
Thanks very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
db-populate 是一个 Rails 插件,它使用 populate.rake 文件,它不是 Rails 的核心功能,所以是的,您需要一个 gem/plugin(http://github.com/ffmike/db-populate)。
然而,由于您已经升级到 Rails 3,现在可能是切换到使用内置 Rails 种子功能的好时机 - 这样就可以轻松运行 rake db:setup ,它将从 database.yml 创建数据库,加载模式,然后运行 seeds.rb 或 rake db:reset ,它在删除数据库后执行相同的操作。也使您无需维护第三方代码。仅供思考。 :)
db-populate is a Rails plugin which uses a populate.rake file, it's not core Rails functionality so yes, you'd need a gem/plugin for it (http://github.com/ffmike/db-populate).
However, since you've upgraded to Rails 3, it might be a nice time to switch to using the built-in Rails seed functionality - that way it's easy to run rake db:setup which will create the db from database.yml, load the schema, and run seeds.rb or rake db:reset which does the same thing after dropping the db. Keeps you from having to maintain third-party code as well. Just food for thought. :)
我从副本仔细重建 populate.rake 文件后发现了问题。我引入到文件中的一些示例文本带有引号,这些引号干扰了属于字符串本身的引号。
一旦 Rails 将字符串解释为已结束,那么它从逻辑上开始在连续的字符串中返回错误,并将其读取为可解释的代码。
一旦我在重建过程中删除了字符串中的所有引号,该文件就开始工作。感谢 Ryan 和 JenJenut 的回复!
I found the problem after carefully reconstructing the populate.rake file from a copy. Some of the sample text I introduced into the file had quotes and these were interfering with the quotes belonging to the string itself.
Once Rails interprets the string as having ended, then it logically starts to return errors within the successive strings, which it is reading as interpretable code.
Once I removed all the quotes from within my strings during that reconstruction, the file started working. Thank you Ryan and JenJenut for your replies!