Tag: rake

如何在Ruby on Rails中为自己的rake任务使用自定义日志?

我有一个rake任务调用这样的函数: namespace :blah do task :hello_world => :environment do logger.info(“Hello World”) helloworld2 end end def helloworld2 logger.info(“Hello Again, World”) end 我希望日志输出到自定义日志,我真的不希望每次进行函数调用时都要传递日志引用。 我发现这个地方(再也找不到了): def logger @@logger ||= Logger.new(“#{RAILS_HOME}/log/blah.log”) end 但是这对我不起作用,我不确定它甚至做了什么,因为我很久以前就抓住了代码并且直到现在才使用它。 我无法在google上搜索@@(尝试+“@@”rails)来查看它的作用。 对这个问题的任何帮助都会很棒。 我希望快速解决方案而不必安装gem或插件(除非有一个非常好的理由。 谢谢!

使database.yml文件在OSX上的Rails中工作

我知道在osx上使用postgres有点困难,因为它有自己的版本运行,所以为了psql到它你需要提供像这样的主机名 psql -h localhost mydatabasename -U me 但是,如何为您的database.yml文件执行此操作以获取所有轨道可爱性。 如果您尝试连接 development: adapter: postgresql username: me database: mydatabasename 你收到了经典 Couldn’t create database for {“adapter”=>”postgresql”, “username”=>”me”, “database”=>”mydatabasename”} could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket “/tmp/.s.PGSQL.5432”? 关于如何提供信息或配置osx的任何想法都不要吮吸这么多?!

捆绑更新rake没有修复我的’你已经激活了rake …’错误

当我在Ubuntu终端中运行rake db:migrate ,我不断收到错误: rake aborted! You have already activated rake 10.0.4, but your Gemfile requires rake 0.9.6. Using bundle exec may solve this. 我在stackoverflow上看到一种解决这个问题的方法是运行: bundle update rake 所以我这样做,我得到: Fetching gem metadata from https://rubygems.org/……. Fetching gem metadata from https://rubygems.org/.. Enter your password to install the bundled RubyGems to your system: Using rake (0.9.6) Using SystemTimer (1.2.3) […]

新手:’rake -T’时出现错误信息

我正在为我的项目使用Ruby Enterprise Edition 。 当我通过运行命令rake -T检查所有rake任务时 ,我收到以下错误消息: You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.9.2. Using bundle exec may solve this. 错误消息暗示我可以使用bundle exec来解决问题,但我不确定如何? 那么,如何摆脱这个错误信息? – – – – – – – – – – – – – – – 更多 – – – – – – – – – – ——– […]

Rails:db / schema.rb中的差异 – null:false:created_at / updated_at列

有人知道为什么每当我在生产环境中运行rake db:migrate时,schema.rb文件都会被更改? 差异仅在所有模型表的created_at,update_at列上: – t.datetime “created_at” – t.datetime “updated_at” + t.datetime “created_at”, null: false + t.datetime “updated_at”, null: false 我知道这是它在生产数据库中找到的,但为什么它们被创建为null: false而不是在开发数据库中?

Rails – 使用rake任务更新属性。 需要帮助排除模型方法代码

我正在尝试使用每晚运行的rake任务(使用Heroku Scheduler)并在满足某些特定条件时更新某些属性。 关于应用程序的一点逻辑: 该应用程序允许用户在一年的时间内“接受挑战”并阅读一周的书。 这很简单:用户注册,创建他们将在第一周阅读的第一本书,然后可以输入他们下周要阅读的内容。 在他们将下周的书排成队之后,这个表格将被隐藏,直到他们的第一本书出版7天。 此时,排队的书被移动到列表的顶部并标记为“当前正在阅读”,而之前的“当前正在阅读”的书则向下移动到列表中的第二个位置。 如果用户没有“排队”一本书,如果自最新的“当前阅读”书籍创建起7天后,系统将自动创建一本书。 我需要一些建议 我目前所困的地方是,如果自上次“当前阅读”书籍创建以来已经过了7天,那么书籍就会更新属性。 下面是我的书模型,方法update_queue是在rake任务期间调用的内容。 运行rake任务当前没有错误并正确循环代码,但它不会更改任何属性值。 所以我确定update_queue方法中的代码在某些地方不正确,我很乐意帮助您解决原因。 我如何测试这个是通过添加一本书然后手动将我的系统日期更改为提前8天。 非常野蛮,但我没有为这个应用程序编写的测试套件,这是最简单的方法为我做:) class Book {:reading => 1}} } scope :latest_first, lambda { {:order => “created_at DESC”} } def move_from_queue_to_reading self.update_attributes(:queued => false, :reading => 1); end def move_from_reading_to_list self.update_attributes(:reading => 0); end def update_queue days_gone = (Date.today – Date.parse(Book.where(:reading => 1).last.created_at.to_s)).to_i # […]

Rake db:放弃我的旧桌子

我的用户迁移过去看起来像这样: class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :login etc 现在它看起来像这样: class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :username etc 那么,为什么我会看到这个? rake db:drop rake db:create rake db:migrate rails console > User.new +—-+——-+——————+—————+——————-+————+————+ | id | login | crypted_password | password_salt | persistence_token | created_at | updated_at | […]

如何将数据从生产数据库迁移到开发数据库(Rails 4)?

我知道这听起来有些倒退! 我一直在研究基于云的案例管理应用程序,并且正在开发支持票务function。 我们的开发数据库(MySQL)拥有与生产数据库相同的所有数据(这是一个非常大的应用程序)。 开发基本上是一个“沙箱”环境,因此开发数据库与生产数据库完全相同。 今天早上,我在本地开发服务器中遇到了一个问题: Migrations are pending; run ‘bin/rake db:migrate RAILS_ENV=development’ to resolve this issue. 好吧,那样做,即使它没有任何意义。 它错了,因为它试图创建已经存在的表(我已经运行了我的迁移,function在一天前完成了!一切都很好)。 在我的开发服务器中收到此消息之前,我唯一能做的就是取消注释一个完全注释掉的文件来尝试修复TinyMCE(/config/tinymce.yml,文本编辑器)的问题,然后重启我的rails开发服务器。 所有这个文件都是一堆默认和插件。 当我看到这个问题时,我首先将它们全部评论回来。 还是一样的错误。 继续rake db:tasks。 开始寻找答案..不断出错。 犯了一个noob错误,最终做了一个 rake db:migrate:reset 我知道会以管理db的方式重建模式。 这失败了..但是我们确实在不止一个地方有数据库(因为它和生产一样)。另外,只是为了尝试将所有表格带回来: rake db:schema:load ….无论如何,在其中一张桌子上失败了 ActiveRecord::StatementInvalid: Mysql2::Error: Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX `login` USING btree ON `users` (`login`, […]

如何强制rake资产:预编译为生产RefineryCMS生成单独的JS文件?

我正在使用RefineryCMS,在管理部分我需要包含一个JS文件。 为此,您必须设置配置值 config.register_javascript “bootstrap.modal” http://antonivanopoulos.com/refinerycms-admin_restyle-a-gem-to-make-refinery-cms-a-little-prettier/ 它在开发中有效。 当我预编译资产以进行生产时,RefineryCMS管理页面会出现404错误,因为bootstrap.modal-7bc4667810e04a7a7ccf02099c81a882.js在公共/资产中不存在。 相反,它嵌入在Refinery管理员不使用的application.js中。 Refinery将为该文件插入单独的JS标记: 该文件作为应用程序资产存在,但不会被指纹识别为其自己的文件。 $ ls app/assets/javascripts/bootstrap.modal.js app/assets/javascripts/bootstrap.modal.js $ rake assets:precompile … $ ls public/assets/boot* ls: cannot access public/assets/boot*: No such file or directory 我不能只包含application.js,因为还有很多东西会破坏管理页面的显示。 我阅读了整个资产管道指南但没有发现任何有用的东西 http://guides.rubyonrails.org/asset_pipeline.html Rails 3.2.14。

heroku rake db:migrate失败

我收到以下错误: [app(master)] $ heroku rake db:migrate 耙子流产了! Heroku :: Rails的未定义方法`root’:Module / app / Rakefile:7 (通过使用–trace运行任务查看完整跟踪)(在/ app中) 我无法弄清楚如何运行跟踪错误建议( heroku rake db:migrate –trace给出“无效选项–trace”),我不相信这与着名的“heroku”有关不使用sqlite3“问题。 我的Rakefile如下: require File.expand_path(‘../config/application’, __FILE__) require ‘rake’ SampleApp::Application.load_tasks