rake

Model.reset_column_information does not reload columns in rails migration

二次信任 提交于 2019-12-17 21:56:16
问题 I'm using Rails 3.2 and have a migration that contains the code: add_column :users, :gift_aid, :integer, :default => 2 # reset columns User.reset_column_information ... code here to load legacy data from sqlite3 database ... # now create a user with the loaded column data user = User.create( ...other cols..., :gift_aid => migrated_gift_aid_column_data, ...other cols... ) and I get unknown attribute: gift_aid when running the migration. User.column_names shows the same list before and after

Why is rake db:migrate:reset not listed in rake -T?

老子叫甜甜 提交于 2019-12-17 21:43:53
问题 Why are some rake tasks not listed by rake -T ? Like db:migrate:reset ? I can execute it without a problem, but why is it not listed there? Is there a way to get a real full list of rake tasks? % rake -T (in /home/zeus/projects/my_project) rake about # List versions of all Rails frameworks and the environment rake db:create # Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config) rake db:drop # Drops the database for the

Where should my non-model/non-controller code live?

一世执手 提交于 2019-12-17 19:38:40
问题 I've written a rails app that follows the regular directory structure (model code in models, controller code in controllers). But I'm now working on a new feature and for that I have written some (what I would call) "service" code. The new feature is to import some data into the system, at the moment it's two classes to do the importing but could expand to more. I don't believe the new code belongs in model as it's not modelling any object (it's not directly related to any single object

Detect if application was started as HTTP server or not (rake task, rconsole etc)

跟風遠走 提交于 2019-12-17 18:55:10
问题 I'm using EventMachine and Monetarily to start e TCP server along with my rails application. This is started from config/initializers/momentarily.rb . My problem is that it starts also when I run rake tasks, like db:migrate . I only want it to start when when I start the HTTP server. Environments won't help, since both the server start and rake tasks are under Development environment. Is there a way of knowing that the application is running the HTTP server as opposed to anything else? Note

Rails 3 rake task can't find model in production

╄→尐↘猪︶ㄣ 提交于 2019-12-17 17:44:20
问题 My simple rake task, stored in lib/tasks/items_spider.rake runs just fine in development. All it does is call spider! on the Item model. namespace :items do desc "Spider the web for data, hoorah" task :spider => :environment do Item.spider! end end I have the :environment task as a dependency, so everything works just fine. However, when I add RAILS_ENV=production , I hit errors, both on my local server and the production server: $ rake items:spider RAILS_ENV=production --trace (in /home

How do I return early from a rake task?

冷暖自知 提交于 2019-12-17 17:28:40
问题 I have a rake task where I do some checks at the beginning, if one of the checks fails I would like to return early from the rake task, I don't want to execute any of the remaining code. I thought the solution would be to place a return where I wanted to return from the code but I get the following error unexpected return 回答1: A Rake task is basically a block. A block, except lambdas, doesn't support return but you can skip to the next statement using next which in a rake task has the same

FactoryGirl screws up rake db:migrate process

北慕城南 提交于 2019-12-17 15:28:03
问题 I am doing TDD/BDD in Ruby on Rails 3 with Rspec (2.11.0) and FactoryGirl (4.0.0). I have a factory for a Category model: FactoryGirl.define "Category" do factory :category do name "Foo" end end If I drop, create then migrate the database in the test enviroment I get this error: rake aborted! Could not find table 'categories' This problem occurs because FactoryGirl expects the tables to already exist (for some odd reason). If I remove the spec folder from my rails app and do db:migrate , it

Global access to Rake DSL methods is deprecated

元气小坏坏 提交于 2019-12-17 15:13:15
问题 I am working through the Ruby on Rails 3 tutorial book and typed the following on the command line: rake db:migrate which produced the following warning. WARNING: Global access to Rake DSL methods is deprecated. Please Include ... Rake::DSL into classes and modules which use the Rake DSL methods. WARNING: DSL method DemoApp::Application#task called at /Users/imac/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/railties-3.0.7/lib/rails/application.rb:215:in `initialize_tasks' I am not sure what

uninitialized constant MysqlCompat::MysqlRes (using mms2r gem)

此生再无相见时 提交于 2019-12-17 10:40:11
问题 moved a rails app of mine onto a new server and had to install a few gem dependencies. However, after installing the mysql gem I get the error, uninitialized constant MysqlCompat::MysqlRes, whenever I try to run a rake command that involves the mysql database. It seems I only get this error when I require the mms2r gem. Has anyone ever heard of this? I'm running mysql 2.8.1 gem. 回答1: on my Mac OS X 10.6 I did this to install the 2.8.1 gem, which worked perfectly with my MacPorts mysql5-server

Rake “already initialized constant WFKV_” warning

試著忘記壹切 提交于 2019-12-17 09:29:09
问题 Trying to run rake cucumber:ok and am getting this error: /Users/dev/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53: warning: already initialized constant WFKV_ Then: Command failed with status (1): [/Users/dev/.rbenv/versions/1.9.2-p290/bin...] I am pretty new to Rails and Google didn't turn anything up for this error. EDIT: I've tried adding bundle exec and that makes no difference. Here's what I got with --trace : /Users/dev/.rbenv