有一个奇怪的问题,需要帮助.
我正在尝试在生产服务器上启动rails控制台,它的行为类似于rails c命令不存在.
FWIW,我已经成为一名铁路开发人员已有4年,并且一直在很多其他服务器上这样做而没有问题.在这台服务器上,我可以毫无问题地删除,创建,迁移,播种数据库(使用RAILS_ENV =生产),并且应用程序可以正常运行而不会出现任何问题.
建立:
Ubuntu 14.04(racksapce第二代性能1服务器)
Nginx with Passenger(我通常使用Unicorn,但从未在我使用Passenger部署的任何应用程序上遇到过问题)
Ruby 2.1.5(使用rvm)
Rails 4.1.7
Postgres
Capistrano 3(使用rvm,迁移,资产预编译等扩展)
我尝试过的:
进入app目录:
cd /home/deployer/app_name/current
Run Code Online (Sandbox Code Playgroud)
哪个加载.rvmrc并显示我在正确的gemset中,运行bundle只是为了踢.
rails c production # (which usually works no problem)
bundle exec rails c production # (sometimes have to do this on older apps that do not have the newer capistrano 3 and rvm setup)
rails c production RAILS_ENV=production # (getting desperate here)
RAILS_ENV=production rails c production # (haha, surely this won't work, but out of options)
RAILS_ENV=production …Run Code Online (Sandbox Code Playgroud) 我有一个在Nginx上运行的应用程序,并且具有如下所示的服务器工作块:
server {
listen 80;
server_name example.com;
root /home/deployer/apps/my_app/current/;
index index.php;
location / {
index index.php;
try_files $uri $uri/;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/home/deployer/apps/shared/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location /foo {
root /home/deployer/apps/modules/;
# tried this:
# alias /home/deployer/apps/modules/foo/;
# but php is not working with alias, only with root
}
}
Run Code Online (Sandbox Code Playgroud)
当我访问/ foo时,Nginx在/ home / deployer / apps / modules / foo /路径中查找index.php文件,它可以工作。
问题:
我使用capistrano设置了一个部署脚本,该脚本部署到foo目录中:
/home/deployer/apps/modules/foo/
Run Code Online (Sandbox Code Playgroud)
Capistrano在'foo'目录中创建一个'current'目录,以包含从Github提取的应用程序文件,因此我需要将根路径更改为:
/home/deployer/apps/modules/foo/current/
Run Code Online (Sandbox Code Playgroud)
但是Nginx将location指令附加到root指令的末尾....因此,当您访问/ foo时,Nginx尝试查找:
/home/deployer/apps/modules/foo/current/foo/ …Run Code Online (Sandbox Code Playgroud) 我有一个Rails 4应用程序,它使用自定义身份验证gem来根据第三方API对用户进行身份验证。该应用程序要求对网站上的大多数操作进行身份验证(访问者可以做的很少)。
我正在尝试使用VCR记录所有集成测试在身份验证期间提出的api请求,但是我可以在SO和Relish文档上找到的所有示例仅涵盖如何在'describe do'规范中使用Rspec进行此操作,如此处所引用:
https://www.relishapp.com/vcr/vcr/v/1-6-0/docs/test-frameworks/usage-with-rspec
由于没有客户参与该项目,因此我正在使用Rspec和Capybara而不是Cucumber编写集成测试,因此我的测试使用的是“功能/场景”格式,如下所示:
feature 'posts' do
scenario 'a user can log in' do
# use vcr for api request
sign_in_user # refers to a method that handles the api call to log in a user, which is what I would like VCR to record.
expect(page).to have_content("User signed in successfully")
end
end
Run Code Online (Sandbox Code Playgroud)
使用文档中描述的命令:
use_vcr_cassette
Run Code Online (Sandbox Code Playgroud)
在“方案”块中,返回错误:
Failure/Error: use_vcr_cassette
undefined local variable or method `use_vcr_cassette' for #<RSpec::ExampleGroups::Posts:0x007fb858369c38>
Run Code Online (Sandbox Code Playgroud)
我按照文档在我的spec / rails_helper.rb(包含在spec / spec_helper.rb中)中设置了VCR ...基本上看起来像这样:
require 'vcr'
VCR.configure do |c|
c.cassette_library_dir = …Run Code Online (Sandbox Code Playgroud) 我有一个带有 jsonb 列的表,该列有一个嵌套的 json 数组。我想找到嵌套数组至少包含一个值的所有记录。
例如,我的模型 Person 有一个名为首选项的 jsonb 列。在 jsonb 首选项中,有几个键,其中一个值是一个数组:
Person.first.preferences = {"diet" => {"foods" => ["apples", "oranges", "bananas"]}}
Run Code Online (Sandbox Code Playgroud)
我想创建一个查询,返回其偏好 -> 饮食 -> 食物包括“苹果”或“芒果”的所有人员(例如)。
目前,我可以通过 1 个输入(即“苹果”)获得结果,如下所示:
Person.where('preferences @> ?', {'diet' => {'foods' => ['apples']}}.to_json)
Run Code Online (Sandbox Code Playgroud)
以及多个输入,如果它们都存在于数组中。因此,如果我传入 'apples' 和 'oranges',则会返回结果,因为该记录同时包含苹果和橙子。
Person.where('preferences @> ?', {'diet' => {'foods' => ['apples', 'oranges']}}.to_json)
Run Code Online (Sandbox Code Playgroud)
有没有办法传入多个变量(即 ['apples', 'mangos'])并检查嵌套的 jsonb 数组是否包含 apples 或 mangos 但不一定两者都包含?
以下查询没有结果,因为我的人的食物偏好不包括芒果,即使它们包括苹果。
Person.where('preferences @> ?', {'diet' => {'foods' => ['apples', 'mangos']}}.to_json)
Run Code Online (Sandbox Code Playgroud)
使用 Rails 5.2 和 Postgresql 10
谢谢!
ruby ×2
activerecord ×1
console ×1
jsonb ×1
nginx ×1
php ×1
postgresql ×1
production ×1
rspec ×1
rspec2 ×1
server ×1
vcr ×1