小编Jer*_*ome的帖子

在Pundit策略中访问会话参数

看来Pundit策略不访问会话参数.由于构造不会将会话重新组合为有效的变量或方法.有没有办法访问会话或其他参数?

class MyModelPolicy
  def create?
    @contructs = Construct.where(['id = ?', session[:construct_id]]).all
  end
end
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails-3.2 pundit

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

capistrano 3不知道如何构建任务'部署:更新'

卡皮斯特拉诺失败了 cap staging deploy

Don't know how to build task 'deploy:updated'
/Users/me/.rvm/gems/ruby-1.9.3-p125@theapp/gems/capistrano-3.1.0/lib/capistrano/dsl/task_enhancements.rb:5:in `before'
Run Code Online (Sandbox Code Playgroud)

Capfile需要按顺序: require 'capistrano/bundler' require 'capistrano/rails' require 'capistrano/rvm'

set :rvm_type, :user
set :rvm_ruby_version, 'ruby-1.9.3-p484'

require 'capistrano/setup'

require 'capistrano/deploy'
Run Code Online (Sandbox Code Playgroud)

我意识到在本地125和远程484之间的rvm上有一个发布版本问题.但是我不确定这是原因./deploy/staging.rb说明

set :stage, :staging
role :app, %w{theapp.domain.tld}
role :web, %w{theapp.domain.tld}
role :db,  %w{theapp.domain.tld}

server '4.44.444.44', user: 'me', roles: %w{web app}
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails-3 capistrano3

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

Rails:Bootsnap 无法加载

今天启动 rails 5 应用程序时,遇到以下错误:

1: from /home/deploy/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/compile_cache/iseq.rb:37:in `load_iseq'
/home/deploy/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/compile_cache/iseq.rb:37:in `fetch': 
Operation not permitted - bs_fetch:atomic_write_cache_file:chmod (Errno::EPERM)
Run Code Online (Sandbox Code Playgroud)

这里的其他问题似乎指向了一个解决方案,其中 gemfile 调用require: false已经指定

gem 'bootsnap', '>= 1.1.0', require: false
Run Code Online (Sandbox Code Playgroud)

应用程序服务器可以启动的唯一方法(目前处于开发模式)是从 boot.rb 注释掉以下行:

# require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
Run Code Online (Sandbox Code Playgroud)

在上次重启(昨天)和现在之间,boot.rb 和 Gemfile 都没有被修改。打开和关闭此行证明问题出在 bootsnap 上。

怎么了?到底是怎么回事?

ruby-on-rails bootsnap

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

wicked-pdf在生成文件时挂起服务器

在rails 3.2.18应用程序中,在gem文件中声明了wicked_pdf(0.11.0)和wkhtmltopdf-binary(0.9.9.3),mime-types.rb 未被修改为包含Mime::Type.register "application/pdf", :pdf否则,在osX开发平台上启动Thin ,给出以下警告:

/Users/it/.rvm/gems/ruby-1.9.3-p125@app/gems/actionpack-3.2.18/lib/action_dispatch/http/mime_type.rb:102: warning: already initialized constant PDF
Run Code Online (Sandbox Code Playgroud)

初始化器声明

WickedPdf.config = {
  :exe_path => '/usr/local/bin/wkhtmltopdf'
}
Run Code Online (Sandbox Code Playgroud)

该路径/usr/local/bin包含wkhtmltopdf的别名.在展示视图中:

  def show
    @transaction = Transaction.find(params[:id])

    respond_to do |format|
      format.html { render :layout => 'pdf' } # show.html.erb
      format.pdf do
        render :pdf => "invoice_name"
      end
      format.json { render json: @transaction }
    end
  end
Run Code Online (Sandbox Code Playgroud)

节目视图呈现得恰当.附加路径.pdf和控制台注册:

"***************[\"/usr/local/bin/wkhtmltopdf\", \"-q\", \"file:///var/folders/kV/kVDOSPkcEuqSVnTjenAVRE+++TI/-Tmp-/wicked_pdf20141018-1401-m614pd.html\", \"/var/folders/kV/kVDOSPkcEuqSVnTjenAVRE+++TI/-Tmp-/wicked_pdf_generated_file20141018-1401-1hor23g.pdf\"]***************"
Run Code Online (Sandbox Code Playgroud)

并且服务器挂起.它被中断,ctrl-c然后服务器控制台添加:

[...]
Rendered transactions/show.pdf.erb (12.1ms)
Rendered text template (0.0ms)
Sent data invoice_name.pdf  (18.8ms) …
Run Code Online (Sandbox Code Playgroud)

macos wicked-pdf ruby-on-rails-3.2

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

同步系统和应用程序之间的依赖关系

出现以下错误

You have already activated strscan 3.0.1, but your Gemfile requires strscan 3.0.3.  
Since strscan is a default gem, you can either remove your dependency on it or try updating to a newer version of bundler that supports strscan as a default gem. (Gem::LoadError)
Run Code Online (Sandbox Code Playgroud)

在哪里bundle -v Bundler version 2.3.13

考虑在 Gemfile 中不直接调用的依赖项。Gemfile.lock 确实声明strscan (3.0.3) strscan 被调用net-imap (0.2.3)

gem update --system
gem update bundler
touch tmp/restart.txt
Run Code Online (Sandbox Code Playgroud)

并不能解决问题。

如何解决这个版本控制问题?通过显式验证或删除依赖关系

ruby-on-rails bundler

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

设置 Rails 内容安全策略

在给定页面上多次调用以下浏览器控制台错误消息

Refused to apply inline style because it violates the following  
Content Security Policy directive: "style-src 'self' https:".  
Either the 'unsafe-inline' keyword, a hash ('sha256-1eLkOKTGLdFR92ElIWA31YdS/7E3GLP3GvnXjSvRz+s='),  
or a nonce ('nonce-...') is required to enable inline execution.  
Note that hashes do not apply to event handlers, style attributes and  
javascript: navigations unless the 'unsafe-hashes' keyword is present.
Run Code Online (Sandbox Code Playgroud)

指的是在初始化程序中设置为股票值的问题,加上对用于本地开发目的的 ngrok 地址的引用

 Rails.application.configure do
   config.content_security_policy do |policy|
     policy.default_src :self, :https, 'https://343e-5-170-92-35.eu.ngrok.io'
     policy.font_src    :self, :https, :data
     policy.img_src     :self, :https, :data
     policy.object_src  :none
     policy.script_src  :self, :https …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails content-security-policy

6
推荐指数
0
解决办法
620
查看次数

Nginx配置导致连接太多

在尝试实现上载进度模块时,以下服务器配置导致打开文件过多错误

2014/11/19 12:10:34 [alert] 31761#0: *1010 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: xxx, request: "GET /documents/15/edit HTTP/1.0", upstream: "http://127.0.0.1:80/documents/15/edit", host: "127.0.0.1"
2014/11/19 12:10:34 [crit] 31761#0: *1010 open() "/usr/share/nginx/html/50x.html" failed (24: Too many open files), client: 127.0.0.1, server: xxx, request: "GET /documents/15/edit HTTP/1.0", upstream: "http://127.0.0.1:80/documents/15/edit", host: "127.0.0.1"
Run Code Online (Sandbox Code Playgroud)

以下是生成冲突passenger_enabled的服务器块的相关部分; rails_env开发; root/home/user/app/current/public;

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

passenger nginx ruby-on-rails-3.2

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

AWS桶和区域

该应用程序正在将gemwave与carrierwave-awsgem 结合使用.在迁移rails版本(升级到4.2),ruby版本(2.2.3)并重新部署到同一个登台服务器时遇到了障碍.

AWS桶最初是在免费层创建的,因此俄勒冈州是us-west-2.但是,我发现所有S3文件都有链接到的属性eu-west-1. 不可否认,我一直在修补并考虑使用eu-west-1地区.但是我不记得进行任何配置更改 - 甚至不确定它是否允许在免费套餐中...

所以是的,我必须配置我的上传初始化程序:

config.asset_host = 'https://s3-eu-west-1.amazonaws.com/theapp'
config.aws_credentials = {
  region:            'eu-west-1'
}
Run Code Online (Sandbox Code Playgroud)

现在可以使用包含的URL访问AWS控制台 region=us-west-2

我不明白这是怎么回事,我正在寻找建议.

amazon-s3 amazon-web-services carrierwave

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

使用css内容在Font Awesome中添加多个图标和空间

我可以通过以下方式使用Font Awesome图标:

.icon-car {
  content: "\f1b9";
}
Run Code Online (Sandbox Code Playgroud)

是否有可能使其包含多个图标(比如\f1b9\f1b8),在一次之间的非打破空间?

css font-awesome

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

rbenv安装不下载ruby版本

使用rbenv安装ruby版本会rbenv install -l返回正确的列表.然而

$ rbenv install 2.3.4 -v
Run Code Online (Sandbox Code Playgroud)

下载失败,即使它可以通过浏览器下载.关于openssl的不正确版本的预感(由于某些遥远的记忆存在这些问题 - 过去的版本? - 在详细模式中支持):

ruby-build: use openssl from homebrew 
/var/folders/kV/kVDOSPkcEuqSVnTjenAVRE+++TI/-Tmp-/ruby-build.20170601122915.1010 ~ Downloading ruby-2.3.4.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.4.tar.bz2 
curl: (35)    error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version 
error: failed to download ruby-2.3.4.tar.bz2
Run Code Online (Sandbox Code Playgroud)

怎么克服?我可以指向rbenv使用下载的tarball吗?

openssl rbenv ruby-on-rails-4

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