Tag: rake task

Rails Rake Task – 访问模型类

我想定义一个Ruby(1.9.2)-on-Rails(3.0.5)rake任务,它将用户添加到User表中。 该文件如下所示: #lib/tasks/defaultuser.rake require 'rake' namespace :defaultuser do task :adduser do u=User.new u.email="bob@example.com" u.password="password" u.save u.errors.each{|e| pe} end end 然后我会调用这个任务 > rake defaultuser:adduser 我在Rails控制台的:adduser任务中testing了代码,并且工作正常。 我testing了rake任务,只能运行 print "defaultuser:adduser" 在任务的主体,它工作正常。 但是,当我把它们结合起来时,它抱怨说 rake aborted! uninitialized constant User 我试过了 require File.expand_path('../../../app/models/user.rb', __FILE__) 在rake文件中的命名空间定义之上,但是这不起作用。 我有 rake aborted! ActiveRecord::ConnectionNotEstablished 我需要做什么以便我在Rails任务中拥有对Rails控制台中User模型类的相同访问权限?

rake db:用postgresql创build编码错误

我正在将一个现有的rails项目导入到我的新的arch linux系统中,我已经正确安装了所有的gem和postgresql,但是在运行时遇到一些问题: rake db:create 我得到以下错误 PGError: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII) HINT: Use the same encoding as in the template database, or use template0 as template. : CREATE DATABASE "System_test" ENCODING = 'unicode' 我用正确的编码方式手动创build了数据库,迁移效果很好,但我可以运行 rake db:test:clone 命令,因为它试图创build一个数据库,我不假设手动创build数据库。 那么,有人知道解决这个问题? 问候 编辑:这是我的database.yml development: adapter: postgresql encoding: unicode database: […]

PG未定义错误关系用户不存在

我以前看到过这个问题,但只是针对rspec。 我不是创buildtesting,因为它对我来说太早了,但有一天我会! :P 我遇到这个错误,当我尝试注册/login与我的应用程序。 我不确定在哪里寻找解决办法。 我使用devise来创build我的用户,也omn​​iauth2login与谷歌 。 这是错误 ActiveRecord::StatementInvalid at /users/auth/google_oauth2/callback PG::UndefinedTable: ERROR: relation "users" does not exist LINE 5: WHERE a.attrelid = '"users"'::regclass ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"users"'::regclass AND […]