小编dhr*_*moy的帖子

Rails 5 - 找不到生成器'rspec:install'

在我的rails 5.0.0应用程序中,我已将以下内容添加到我的Gemfile中:

group :development, :test do
  gem 'byebug', platform: :mri
  gem 'rspec-rails', '~> 3.5', '>= 3.5.2'
end
Run Code Online (Sandbox Code Playgroud)

我跑bundle install.然后gem成功安装.

然后我跑了以下:

rails generate rspec:install
Run Code Online (Sandbox Code Playgroud)

但我得到一个错误说:

Running via Spring preloader in process 8893
Could not find generator 'rspec:install'. Maybe you meant 'css:assets', 'assets' or 'scaffold'
Run `rails generate --help` for more options.
Run Code Online (Sandbox Code Playgroud)

在这个错误(Could not find generator 'rspec:install')上发布了大量其他问题,但它们都没有为我工作,看起来我有一个不同的问题.

包括它需要的,这是我的bundle show输出:

Gems included by the bundle:
  * actioncable (5.0.0.1)
  * actionmailer (5.0.0.1)
  * actionpack (5.0.0.1)
  * actionview (5.0.0.1) …
Run Code Online (Sandbox Code Playgroud)

ruby rspec ruby-on-rails ruby-on-rails-5

6
推荐指数
1
解决办法
3908
查看次数

在java中增加char数据类型

我有以下代码

 class arr
  { 
    public static void main(String a[])
     {
       char c='A';
       c+=10;
        System.out.println(c);
        }
     } 
Run Code Online (Sandbox Code Playgroud)

从java 8编译时,它编译成功.

output ķ

但是当我编译下面的代码时:

class arr
{ 
  public static void main(String a[])
   {
    char c='A';
      c=c+10;
      System.out.println(c);
    }
 } 
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

  logic.java:6: error: incompatible types: possible lossy conversion from int to char
  c=c+10;
    ^
Run Code Online (Sandbox Code Playgroud)

我不明白c=c+10,c+=10为什么我会收到这样的错误?请帮我.谢谢.

java

2
推荐指数
1
解决办法
146
查看次数

如何递归地将作为符号的Ruby Hashes的键转换为String

假设我有以下哈希或嵌套哈希:

h = { :a1 => { :b1 => "c1" },
      :a2 => { :b2 => "c2"},
      :a3 => { :b3 => "c3"} }
Run Code Online (Sandbox Code Playgroud)

我想创建一个方法,将哈希作为参数,并递归地将所有键(例如符号的键:a1)转换为String(例如"a1").到目前为止,我已经提出了以下方法,它不起作用并返回{"a1"=>{:b1=>"c1"}, "a2"=>{:b2=>"c2"}, "a3"=>{:b3=>"c3"}}.:

def stringify_all_keys(hash)
    stringified_hash = {}
    hash.each do |k, v|
        stringified_hash[k.to_s] = v
        if v.class == Hash
            stringify_all_keys(stringified_hash[k.to_s])
        end
    end
    stringified_hash
end
Run Code Online (Sandbox Code Playgroud)

我做错了什么以及如何将所有键转换为字符串,如下所示:

{"a1"=>{"b1"=>"c1"}, "a2"=>{"b2"=>"c2"}, "a3"=>{"b3"=>"c3"}}
Run Code Online (Sandbox Code Playgroud)

ruby recursion hash

1
推荐指数
2
解决办法
1611
查看次数

nginx反向代理以避免本地主机出现cors错误

我正在使用 gulp 服务器进行本地前端开发,我连接到的应用程序正在另一台服务器上运行,包括前端和后端。

gulp 服务器在 localhost:1340 上运行。api 位于https://aaa.bbb.com/api

我收到以下错误: No 'Access-Control-Allow-Origin' header is present on the requested resource.

所以我尝试使用nginx设置一个反向代理服务器,这样我将在localhost:8001上启动一个nginx服务器,它充当gulp服务器和api之间的连接。

这是来自 nginx.conf 的设置

server { # simple reverse-proxy
    listen       8001;
    server_name  localhost;
    # access_log   logs/domain2.access.log  main;


    location / {
      proxy_pass      http://localhost:1340;
      proxy_set_header Host $http_host;
      add_header Access-Control-Allow-Origin *;


      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-NginX-Proxy true;

    }
    location /api/ {
      proxy_pass      https://aaa.bbb.com/api/;
      add_header Access-Control-Allow-Origin *;

      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;



      proxy_redirect off;

    } …
Run Code Online (Sandbox Code Playgroud)

nginx cors

1
推荐指数
1
解决办法
6583
查看次数

标签 统计

ruby ×2

cors ×1

hash ×1

java ×1

nginx ×1

recursion ×1

rspec ×1

ruby-on-rails ×1

ruby-on-rails-5 ×1