简体   繁体   English

rake db:populate是否在Rails 3中工作?

[英]Does rake db:populate work in Rails 3?

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. 我的populate.rake文件遇到了很大的问题-从Rails 2.3.5安装导入现有文件后,Rails 3不再需要处理它。 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? Rails 3填充的语法是否已更改,或者是否需要为其安装gem / plugin?

Thanks very much. 非常感谢。

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). db-populate是一个Rails插件,它使用populate.rake文件,它不是Rails的核心功能,因此,是的,您需要一个gem / plugin(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. 但是,由于您已升级到Rails 3,因此可能是切换到使用内置Rails种子功能的好时机-这样一来,可以很容易地运行rake db:setup,它将从database.yml创建数据库,加载模式,然后运行seed.rb或rake db:reset,在删除数据库后执行相同的操作。 Keeps you from having to maintain third-party code as well. 也使您不必维护第三方代码。 Just food for thought. 值得深思。 :) :)

I found the problem after carefully reconstructing the populate.rake file from a copy. 从副本中仔细重建populate.rake文件后,我发现了问题。 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. 一旦Rails将字符串解释为已结束,则它在逻辑上开始返回连续字符串内的错误,并将其读取为可解释的代码。

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! 谢谢Ryan和JenJenut的回复!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM