小编use*_*922的帖子

如何从Rails中的哈希列表中删除嵌套键

我现在正在尝试删除哈希列表的嵌套哈希键几个小时.我看到很多解决方案非嵌套哈希,如下所示:

   sample_hash = {"key1" => "value1", "key2" => "value2"}
   sample_hash.except("key1") 
Run Code Online (Sandbox Code Playgroud)

这导致:

  {"key2"=>"value2"}
Run Code Online (Sandbox Code Playgroud)

但是如果我尝试在带有嵌套键的哈希上使用except方法,那么它就不起作用了.这是我的代码:

  nested_hash = {"key1"=>"value1", "key2"=>{
                                           "nested_key1"=>"nestedvalue1",
                                           "nested_key2"=>"nestedvalue2"
                                           }
                }

  nested_hash.except("nested_key2")
Run Code Online (Sandbox Code Playgroud)

except()方法返回nested_hash而不做任何更改.我已经找到了一个解决方案,我可以将嵌套的哈希键传递给except方法,但找不到任何东西.是否可以将嵌套键传递给此方法,还是应该使用其他方法从哈希列表中删除嵌套哈希键?

hash nested ruby-on-rails key except

6
推荐指数
2
解决办法
4442
查看次数

Rails 3.2 Nginx Unicorn总是尝试从公共文件夹加载index.html(403)

我刚刚设置了一个Nginx和unicorn服务器fpr我的rails应用程序.直到现在一切顺利.两台服务器都在启动,我可以通过我的URL访问它们.但我的问题是nginx总是从公共文件夹加载index.html作为起始页面.如果我删除index.html文件,那么请求会导致403 Forbidden错误.当我尝试其他路线时,它会导致404找不到错误.所以我假设nginx和unicorn服务器之间没有连接.也许我错了.试图解决这个问题几个小时但没有成功.如果有人可以帮助我,那将是非常好的.

这是我的配置:

nginx.comfig:

/etc/nginx/conf.d/medinow.conf

upstream unicorn {
  server unix:/tmp/unicorn.medinow.sock fail_timeout=0;
}

server {
  listen 80 default deferred;
  # server_name example.com;
  root /var/www/medinow/current/public;

  location / {
    gzip_static on;
  }

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @unicorn;
  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}
Run Code Online (Sandbox Code Playgroud)

unicorn.conf.rb:

worker_processes 4

APP_PATH = "/var/www/medinow/current"
working_directory APP_PATH # available …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails nginx unicorn http-status-code-403

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