我正在尝试运行rails(4.1.2)控制台
rails c RAILS_ENV=test
Run Code Online (Sandbox Code Playgroud)
我得到了这个:
> config.eager_load is set to nil. Please update your
> config/environments/*.rb files accordingly:
>
> * development - set it to false * test - set it to false (unless
> you use a tool that preloads your test environment) * production -
> set it to true
>
> /Users/xxxxxx/.rvm/gems/ruby-2.2.2/gems/activerecord-4.1.12/lib/active_record/connection_adapters/connection_specification.rb:257:in
> `resolve_symbol_connection': 'RAILS_ENV=test' database is not
> configured. Available: ["development", "test", "production"]
> (ActiveRecord::AdapterNotSpecified)
Run Code Online (Sandbox Code Playgroud)
然而,在我的test.rb我config.eager_load = false和我database.yml …
在heroku(heroku run console...)中运行控制台时出现以下错误.应用程序运行没有问题,但我似乎无法运行控制台,因为这和开发中我没有这个问题.
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- test/unit/testcase (LoadError)
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `block in require'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in `load_dependency'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/test_case.rb:1:in `<top (required)>'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `block in require'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in `load_dependency'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/console/app.rb:2:in `<top (required)>'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `block in require'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:236:in `load_dependency'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:251:in `require'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application.rb:304:in `initialize_console'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application.rb:152:in `load_console'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:27:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require' …Run Code Online (Sandbox Code Playgroud) 我有这5个模型:卫报,学生,关系,关系类型和学校.在他们之间,我有这些联想
class Guardian < ActiveRecord::Base
belongs_to :school
has_many :relationships, :dependent => :destroy
has_many :students, :through => :relationships
end
class Student < ActiveRecord::Base
belongs_to :school
has_many :relationships, :dependent => :destroy
has_many :guardians, :through => :relationships
end
class Relationship < ActiveRecord::Base
belongs_to :student
belongs_to :guardian
belongs_to :relationship_type
end
class School < ActiveRecord::Base
has_many :guardians, :dependent => :destroy
has_many :students, :dependent => :destroy
end
class RelationshipType < ActiveRecord::Base
has_many :relationships
end
Run Code Online (Sandbox Code Playgroud)
我想写一个定义关系的FactoryGirl.每个关系都必须有一个监护人和一个学生.这两个人必须属于同一所学校.监护人工厂与学校有联系,学生工厂也是如此.我一直无法让他们在同一所学校建造.我有以下代码:
FactoryGirl.define do
factory :relationship do
association :guardian
association :student, :school => …Run Code Online (Sandbox Code Playgroud) 我有一个问题和两个包括它的类.在关注中,我定义了一个变量.这是关注和两个模型:
module UserInstance
extend ActiveSupport::Concern
included do
ACTIVE = 'active'
end
end
class Guardian < ActiveRecord::Base
include UserInstance
end
class Student < ActiveRecord::Base
include UserInstance
end
Run Code Online (Sandbox Code Playgroud)
我收到这个警告:
/app/app/models/concerns/user_instance.rb:12: warning: already initialized constant UserInstance::ACTIVE
/app/app/models/concerns/user_instance.rb:12: warning: previous definition of ACTIVE was here
Run Code Online (Sandbox Code Playgroud)
我想,一旦它加载一个类(如Guardian),它也加载常量,加载另一个类尝试再次加载常量,然后给出警告.如何在不必将常量放入两个模型的情况下避免这种情况?谢谢
如何使用.bash_profileReact应用程序中定义的环境变量?我在生产中有两个React应用程序(它们是相同的项目,因此它们具有相同的代码),但是它们需要请求不同的API主机,并且我认为env变量可以做到这一点.
有没有办法找出heroku web dyno使用了多少内存?假设我想写一个定期运行的rake任务并检查每个dyno的内存使用情况.我怎么能这样做?谢谢!
我想在API模式下使用Jbuilder和Rails 5.0.0.beta1.1.开箱即用,即使在创建app/views目录时它也不起作用.
例如,我有:
# app/controllers/tests_controller.rb
class TestsController < ApplicationController
# The requests gets inside the action
def test
end
end
# app/views/tests/test.json.jbuilder
json.test "It works!"
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
No template found for TestsController#test, rendering head :no_content
我想我必须改变配置文件中的一些东西.我需要做什么?
自从我们更新到Rails 3.2.13以来,我们一直无法启动heroku rails控制台.服务器运行正常,但是当我们尝试运行控制台时,它会出现以下错误:
Loading production environment (Rails 3.2.13)
/app/vendor/bundle/ruby/1.9.1/gems/aws-s3-0.6.3/lib/aws/s3/extensions.rb:212:in `const_missing_from_s3_library': uninitialized constant IRB::ReadlineInputMethod::Readline (NameError)
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb/input-method.rb:113:in `gets'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb.rb:139:in `block (2 levels) in eval_input'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb.rb:273:in `signal_status'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb.rb:138:in `block in eval_input'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb/ruby-lex.rb:188:in `call'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb/ruby-lex.rb:188:in `buf_input'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb/ruby-lex.rb:103:in `getc'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb/slex.rb:205:in `match_io'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb/slex.rb:75:in `match'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb/ruby-lex.rb:286:in `token'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb/ruby-lex.rb:262:in `lex'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb/ruby-lex.rb:233:in `block (2 levels) in each_top_level_statement'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top_level_statement'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_statement'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb.rb:155:in `eval_input'
from /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/irb.rb:70:in `block …Run Code Online (Sandbox Code Playgroud) 我正在使用Heroku + RedisToGo + Resque.我有一个正在运行非结束任务的工人.我想要记录它的活动.heroku logs --tail没有显示有关工人活动的任何信息.我怎样才能做到这一点?谢谢!
我在该eu-west-1地区有一个 S3 存储桶,我们称之为my-bucket.
在那个桶里有一张照片,我们称之为some-file.jpg。
如果我通过浏览器访问这两个 url,我可以检索该图片(存储桶中的所有对象都是公开的)(请记住,这些是示例,而不是现实生活中的 url):
https://my-bucket.s3.amazonaws.com/some-file.jpg
https://s3-eu-west-1.amazonaws.com/my-bucket/some-file.jpg
但是,我正在尝试获取有关该图片的一些信息,为此我使用了 vibrity.js,它尝试检索该文件。
但是,当 url 为https://my-bucket.s3.amazonaws.com/some-file.jpg时它会失败,并出现以下 CORS 错误:
Access to Image at 'https://my-bucket.s3.amazonaws.com/some-file.jpg' from origin 'https://example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://example.com' is therefore not allowed access
Run Code Online (Sandbox Code Playgroud)
我已确保存储桶的 CORS 策略接受所有来源:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Run Code Online (Sandbox Code Playgroud)
我的猜测是https://s3-eu-west-1.amazonaws.com/my-bucket/some-file.jpg发送Access-Control-Allow-Origin而另一个没有。我该如何解决这个问题?
heroku ×4
amazon-s3 ×1
config ×1
cors ×1
environment ×1
factory-bot ×1
javascript ×1
logging ×1
reactjs ×1
resque ×1
ruby ×1