小编Phi*_*lip的帖子

Nginx缓存 - 图片,获得404

我正在尝试设置nginx来缓存静态文件,例如图像,css和js.

这是我的conf.

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /var/www/site;
        index  index.html index.htm;
  }

        location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
                expires max;
                add_header Pragma public;
                add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}
}
Run Code Online (Sandbox Code Playgroud)

当我尝试使用它时,我在所有文件上获得404,当我删除位置〜*...我可以完美地检索所有文件.我有我的文件/var/www/site/images/*/*.jpg.我在这里错过了什么?

static caching nginx cache-control

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

Rails 4,Live Streaming,保持打开状态,阻止请求

我正在尝试使用Rails 4 Live Streaming组件.这一切都有效,除了它似乎流保持打开并阻止新的请求.

关闭或单击应用程序中的新链接时,如何确保连接正常关闭?

这是我的直播活动控制器.

  def events
    response.headers["Content-Type"] = "text/event-stream"
    redis = Redis.new
    redis.psubscribe("participants.*") do |on|
      on.pmessage do |pattern, event, data|
        response.stream.write("event: #{event}\n")
        response.stream.write("data: #{data}\n\n")
      end
    end
  rescue IOError
  ensure
    redis.quit
    response.stream.close
  end
Run Code Online (Sandbox Code Playgroud)

数据库conf

production:
  adapter: postgresql
  encoding: unicode
  database: ************
  pool: 1000
  username: ************
  password: ************
  timeout: 5000
Run Code Online (Sandbox Code Playgroud)

我在使用postgresql 9.2.x的Ubuntu 10.04上使用puma作为独立的webserver(我没有需要由nginx提供的大量静态文件).

ruby-on-rails http-live-streaming puma ruby-on-rails-4

7
推荐指数
2
解决办法
3027
查看次数

Rails,Sidekiq - Redis NOAUTH

我在rails上使用sidekiq发送电子邮件.我已经为redis服务器添加了密码,但似乎无法正确使用,因为我收到了错误

D, [2015-12-10T16:49:52.714279 #10497] DEBUG -- :    (0.5ms)  COMMIT
I, [2015-12-10T16:49:52.720380 #10497]  INFO -- : [ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: 5bce215c-7649-4774-8c6e-d29e743cf25e) to Sidekiq(mailers) with arguments: "MessageMailer", "new_message", "deliver_now", gid://customer-app/Message/18
I, [2015-12-10T16:49:52.723400 #10497]  INFO -- : Completed 500 Internal Server Error in 25ms (ActiveRecord: 1.6ms)
F, [2015-12-10T16:49:52.726204 #10497] FATAL -- :
Redis::CommandError (NOAUTH Authentication required.):
  app/controllers/messages_controller.rb:37:in `block in create'
  app/controllers/messages_controller.rb:35:in `create'
Run Code Online (Sandbox Code Playgroud)

我的sidekiq日志显示它应该没问题?

2015-12-10T16:49:39.220Z 10448 TID-ows27pimw INFO: Booting Sidekiq 3.5.3 with redis options {:url=>"redis://localhost:6379/0", :password=>"REDACTED", :namespace=>"sidekiq"}
2015-12-10T16:49:40.916Z 10448 TID-ows27pimw INFO: Running in …
Run Code Online (Sandbox Code Playgroud)

authentication ruby-on-rails redis sidekiq

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

未声明框架文档的字符编码

在开发我的网站时,我在FF中收到此警告.我找不到任何关于它的真实信息以及如何解决这个问题.

the character encoding of a framed document was not declared. The document may appear different if viewed without the document framing it.


...e)});else for(var g in a)ca(g,a[g],c,e);return d.join("&").replace(bD,"+")}}),f....
Run Code Online (Sandbox Code Playgroud)

jquery .... min.js(第4行)

firefox document character-encoding declare

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

Ruby on rails,多次检查nil属性

我正在尝试检查nil的多个属性,我发现这篇文章简化了......但我没有得到我想要的结果.我有一个用户,如果需要,我想更新他们的个人资料.但是,该用户拥有我想要的所有数据.

  @user.try(:age_id).nil?
    #returns false
  @user.try(:customer).nil?
    #returns false
  @user.try(:country).nil? 
    #returns false

  @user.try(:age_id).try(:customer).try(:country).nil?
    #returns true
Run Code Online (Sandbox Code Playgroud)

当所有其他尝试的单个实例都以false响应时,为什么它在此处响应为true?

attributes ruby-on-rails ruby-on-rails-4

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

Friendly_id有两个参数?

我想知道是否有一种简单的方法来使用friendly_id并且有两个参数而不是一个,像这样?

www.example.com/dateTitle/

日期和标题是我的数据库中的两个单独字段.

database ruby-on-rails friendly-id

5
推荐指数
2
解决办法
1906
查看次数

Rails - 超类不匹配

使用Rails和控制器继承.

我创建了一个名为的控制器AdminController,其中有一个名为admin_user_controllerplace 的子类/app/controllers/admin/admin_user_controller.rb

这是我的routes.rb

  namespace :admin do
    resources :admin_user # Have the admin manage them here.
  end
Run Code Online (Sandbox Code Playgroud)

应用程序/控制器/管理/ admin_user_controller.rb

class AdminUserController < AdminController
  def index
    @users = User.all
  end
end
Run Code Online (Sandbox Code Playgroud)

应用程序/控制器/ admin_controller.rb

class AdminController < ApplicationController

end
Run Code Online (Sandbox Code Playgroud)

我有一个用户模型,我想用管理员权限编辑.

当我尝试连接到: http://localhost:3000/admin/admin_user/

我收到此错误:

superclass mismatch for class AdminUserController
Run Code Online (Sandbox Code Playgroud)

ruby inheritance routes model ruby-on-rails

5
推荐指数
2
解决办法
5344
查看次数

CarrierWave - PDF - 仅选择第一页

我在rails应用程序中安装了carrierwave.但是,当用户上传多页pdf时,我只希望应用程序获取文档中的第一页并将其转换为jpeg.这可能吗,用什么命令?

这是我的上传者.

# encoding: utf-8

class ImageUploader < CarrierWave::Uploader::Base

  # Include RMagick or MiniMagick support:
  include CarrierWave::RMagick
  include CarrierWave::MimeTypes
  # include CarrierWave::MiniMagick

  # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
  include Sprockets::Helpers::RailsHelper
  include Sprockets::Helpers::IsolatedHelper

  # Choose what kind of storage to use for this uploader:
  storage :file
  # storage :fog

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" …
Run Code Online (Sandbox Code Playgroud)

ruby pdf ruby-on-rails carrierwave

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

Ruby On Rails,周数不正确(-1)

我需要当前的周数,如果我没有完全弄错,现在是第51周?但是,当在控制台中测试时,我得到了这个.

Time.now
=> 2013-12-19 11:08:25 +0100
Time.now.strftime('%U')
=> "50"

Date.today
=> Thu, 19 Dec 2013
Date.today.strftime("%U").to_i
=> 50
Run Code Online (Sandbox Code Playgroud)

这是为什么?

ruby ruby-on-rails week-number ruby-on-rails-4

5
推荐指数
3
解决办法
1349
查看次数

Rails存在?不区分大小写

Model.exists?("lower(email) = ?", params[:email].downcase)
Run Code Online (Sandbox Code Playgroud)

返回错误: ArgumentError (wrong number of arguments (2 for 0..1)):

是否可以使用不exists?区分大小写的匹配?

ruby ruby-on-rails exists case-insensitive

5
推荐指数
2
解决办法
1592
查看次数