Wicked-PDF没有显示图像,’wicked_pdf_image_tag’未定义

我想生成一个包含我们部门徽标的PDF。 当我尝试在我的控制器中使用WickedPdf类时(使用https://github.com/mileszs/wicked_pdf中描述的方法): def some_action image_tag_string = image_tag(‘logo.jpg’) pdf = WickedPdf.new.pdf_from_string(image_tag_string) save_path = Rails.root.join(‘testpdfs’,’logotest.pdf’) File.open(save_path, ‘wb’) do |file| file << pdf end end …应用程序将PDF保存到目标目录,但它有一个蓝白色的’?’ 标记图像应该在哪里。 如果我这样做: image_tag_string = wicked_pdf_image_tag(‘logo.jpg’) pdf = WickedPdf.new.pdf_from_string(image_tag_string) 我收到以下错误: NoMethodError: undefined method `wicked_pdf_image_tag’ for #<… 看来我的Rails应用程序也缺少/没有链接到属于wicked-pdf gem的帮助文件。 StackOverflow上类似问题的答案建议编写自定义“图像标记”帮助程序来定位图像或安装wkhtmltopdf。 对我来说,当放置在View(whatever.html.erb)中时,image-tag显示徽标就好了。 “logo.jpg”已经位于资产管道和#{RailsRoot} / public / images中。 最后,我在Ubuntu 14.04上使用wkhtmltopdf 0.9.9,wicked-pdf 0.11.0和rails 4。 简而言之 – 我做错了什么导致WickedPDF无法渲染图像?

在服务器端validation应用内购买Android / Google

我想在Android应用程序中使用应用内购买的购买令牌来validation我自己的服务器上的谷歌服务器。 使用以下代码,我可以validation令牌,但每次都必须使用我的OAuth凭据对自己进行身份validation: class GooglePlayVerification require ‘google/api_client’ # Refer: # https://code.google.com/p/google-api-ruby-client/issues/detail?id=72 # and # http://jonathanotto.com/blog/google_oauth2_api_quick_tutorial.html # and # http://milancermak.wordpress.com/2012/08/24/server-side-verification-of-google-play-subsc/ GOOGLE_KEY = ‘xxx.apps.googleusercontent.com’ GOOGLE_SECRET = ‘xxxx’ APP_NAME = ‘xx.xx.xx’ SCOPE = “https://www.googleapis.com/auth/androidpublisher” def self.token @@token ||= begin require ‘oauth2’ raise “Missing client_id variable” if GOOGLE_KEY.to_s.empty? raise “Missing client_secret variable” if GOOGLE_SECRET.to_s.empty? raise “Missing scope variable” if SCOPE.to_s.empty? […]

你如何解救I18n :: MissingTranslationData?

我希望能够拯救I18n::MissingTranslationData如下所示: begin value = I18n.t(‘some.key.that.does.not.exist’) puts value return value if value rescue I18n::MissingTranslationData puts “Kaboom!” end 我尝试了以上,但它似乎没有进入救援区。 我只是看到,在我的控制台上(因为puts ): translation missing: some.key.that.does.not.exist 。 我从未见过Kaboom! 。 我如何让它工作?

如何在Rails中获取mb中ruby对象的大小?

我想查询ActiveRecord模型,修改它,并以mb计算新对象的大小。 我该怎么做呢?

你什么时候需要将参数传递给`Thread.new`?

在线程外部定义的局部变量似乎从内部可见,因此Thread.new的以下两个用法看起来是相同的: a = :foo Thread.new{puts a} # => :foo Thread.new(a){|a| puts a} # => :foo 该文件给出了一个例子: arr = [] a, b, c = 1, 2, 3 Thread.new(a,b,c){|d, e, f| arr << d << e < [1, 2, 3] 但由于a , b , c在创建的线程内部是可见的,因此它也应该与: arr = [] a, b, c = 1, 2, 3 Thread.new{d, e, […]

Rspec测试CSV文件下载

我想确保我的CSV下载包含正确的列。 当我使用RSpec测试CSV下载时,我无法访问文件内容。 如何访问CSV文件的内容? require ‘spec_helper’ include Devise::TestHelpers describe Admin::ApplicationsController do before(:each) do @application = FactoryGirl.create :application @user = FactoryGirl.create( :admin_user ) sign_in @user end it “downloads a csv” it “gives us only the columns we want” do get :index, format: :csv p response.body p response.headers end end 测试的输出: # This is the output in the […]

使用/.*?/有什么好处

在一些Rails代码(黄瓜function的步骤定义,javascripts, rails_admin gem)中,我发现了这个正则表达式部分: string =~ /some regexp.+rules should match “(.*?)”/i 我对正则表达式有一些了解,我知道*和? 符号类似,但星号表示zero and more ,问号表示could be present or could be not 。 因此,使用符号组附近的问号使其在被测试的短语中不存在。 什么是……嗯…在非必需已经组附近使用它的技巧(跳过要求是使用星号afaik)?

如何在Rails 4中正确设置database.yml文件

我很好奇如何在Rails 4应用程序中正确设置我的database.yml文件。 这不是我真正详细研究的内容,因为它在部署到Heroku时似乎只是工作,但我现在想要了解它,并注意到格式从Rails 4.0改为4.1。 例如 4.0.2 development: adapter: mysql2 encoding: utf8 database: my_app_development pool: 5 username: root password: test: adapter: mysql2 encoding: utf8 database: my_app_test pool: 5 username: root password: production: adapter: mysql2 encoding: utf8 database: ymca_gym_production pool: 5 username: root password: 4.1.0 default: &default adapter: mysql2 encoding: utf8 pool: 5 username: root password: socket: […]

迭代多个数组的最佳方法是什么?

在Ruby中迭代多个数组的最佳方法(性能方面的美观和高效)是什么? 假设我们有一个数组: a=[x,y,z] b=[‘a’,’b’,’c’] 我想要这个: xa yb zc 谢谢。

哈希中数组的YAML缩进

我认为缩进在YAML中很重要。 我在irb测试了以下内容: > puts({1=>[1,2,3]}.to_yaml) — 1: – 1 – 2 – 3 => nil 我期待这样的事情: > puts({1=>[1,2,3]}.to_yaml) — 1: – 1 – 2 – 3 => nil 为什么数组没有缩进? 我在http://www.yaml.org/YAML_for_ruby.html#collections找到了这个。 序列中的破折号计为缩进,因此您可以在映射内添加序列,而不需要空格作为缩进。