小编Mic*_*tor的帖子

Prawn :: Errors :: IncompatibleStringEncoding:您的文档包含与Windows-1252字符集不兼容的文本

下面是我的Prawn PDF文件,用于在PDF上生成名称 -

def initialize(opportunity_application)
  pdf = Prawn::Document.new(:page_size => [1536, 2048], :page_layout => :landscape)
  cell_1 = pdf.make_cell(content: "Eylül Çamc?".force_encoding('iso-8859-1').encode('utf-8'), borders: [], size: 66, :text_color => "000000", padding: [0,0,0,700], font: "app/assets/fonts/opensans.ttf")

  t = pdf.make_table [[cell_1]]
  t.draw
  pdf.render_file "tmp/mos_certificates/application_test.pdf"
end
Run Code Online (Sandbox Code Playgroud)

当呈现土耳其语名称EylülÇamcı时,我收到以下错误 -

Prawn::Errors::IncompatibleStringEncoding: Your document includes text that's not compatible with the Windows-1252 character set.
If you need full UTF-8 support, use TTF fonts instead of PDF's built-in fonts.
Run Code Online (Sandbox Code Playgroud)

我已经使用支持该名称中字符的TTF字体,我该怎么做才能正确打印名称?

pdf fonts ruby-on-rails utf-8 prawn

23
推荐指数
2
解决办法
2312
查看次数

存储嵌套JSON的访问器

我有"组织"模型,它存储与组织相关的所有信息.有一个名为"集成"的JSONB类型的字段,用于存储与组织具有的所有外部服务集成有关的信息.

如何使用存储访问器访问存储在嵌套JSON中的信息,例如:

{
 "mailchimp": {"api_key":"vsvsvef", "list_id":"12345"},
 "sendgrid" : {"username":"msdvsv", "password":"123456"}
}
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用这样的商店访问器访问mailchimp:

store_accessor :integrations, :mailchimp
Run Code Online (Sandbox Code Playgroud)

如何轻松访问mailchimp的api_key?

activerecord json ruby-on-rails jsonb

19
推荐指数
2
解决办法
9847
查看次数

Cordova Ionic - App意外停止了

Ardoid应用程序意外停止.

控制器文件的链接是:https://www.dropbox.com/s/d0lc34q3mzlgfkj/controllers.js?dl = 0

我将OSX更新为El capitan后出现问题.在更新之前,应用程序将在模拟器中完美启动.现在,即使我构建了APK并尝试将其安装在手机上,也无法安装.

下面是我的日志文件的图像:

在此输入图像描述

我究竟做错了什么?

android cordova ionic-framework

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

将每个实体葡萄放在一个文件中

我想在葡萄实体文件中有多个类,这是文件夹结构app/api/proj/api/v2/entities/committees.rb

module PROJ::API::V2::Entities
class Committee < Grape::Entity
expose :id

expose :name, :full_name, :email, :tag, :parent_id

expose :country do |entity, option|
  entity.parent.name if entity.parent.present?
end

# include Urls

private
  def self.namespace_path
    "committees"
  end
end

  class CommitteeWithSubcommittees < CommitteeBase
        # include ProfilePhoto 
        expose :suboffices, with: 'PROJ::API::V2::Entities::CommitteeBase'
      end
Run Code Online (Sandbox Code Playgroud)

在Grape API中

present @committees, with: PROJ::API::V2::Entities::Committee
Run Code Online (Sandbox Code Playgroud)

工作中.但如果我在场

present @committees, with: PROJ::API::V2::Entities::CommitteeList
Run Code Online (Sandbox Code Playgroud)

它不起作用.但是当我将它移动到一个名为committee_list.rb实体内部的新文件时,它会起作用.

entity ruby-on-rails ruby-on-rails-3 grape-api

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

Vagrant的权限被拒绝错误

我犯了一次运行"sudo vagrant up"的错误,现在每当我运行"vagrant up"时它会给我以下错误

==> default: Running cleanup tasks for 'chef_solo' provisioner...
/opt/vagrant/embedded/gems/gems/vagrant-1.7.1/lib/vagrant/environment.rb:492:in `initialize':   P Permission denied - /Users/mkv/.vagrant.d/data/lock.fpcollision.lock (Errno::EACCES)
Run Code Online (Sandbox Code Playgroud)

我已经尝试删除.vagrant文​​件夹和Cheffile但我总是得到同样的错误.

我该怎么做才能解决这个问题?

permissions vagrant

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

Ionic - Splash Screen适用于iOS,但不适用于Android

我有一个离子应用程序,其中启动屏幕和使用CLI命令生成的图标 ionic resources

iOS版本与正在渲染的启动画面完美配合,但在Android版本中,加载应用程序时只显示白屏.

我检查了config.xml文件,所有路径看起来都是正确的,生成的图像出现在相应的文件夹中.(我使用了splash.psd模板来生成它们.

我错过了什么?

这是config.xml供参考的文件,我觉得我在这里做错了 -

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.testeduser720691" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>Tested Health</name>
  <description>
        An Ionic Framework and Cordova project.
    </description>
  <author email="you@example.com" href="http://example.com.com/">
      Your Name Here
    </author>
  <content src="index.html"/>
  <access origin="*"/>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="android-minSdkVersion" value="16"/>
  <preference name="BackupWebStorage" value="none"/>
  <preference name="SplashScreen" value="screen"/>
  <preference name="SplashScreenDelay" value="3000"/>
  <feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" onload="true"/>
  </feature>
  <platform name="android">
    <icon src="resources/android/icon/drawable-ldpi-icon.png" density="ldpi"/>
    <icon src="resources/android/icon/drawable-mdpi-icon.png" density="mdpi"/>
    <icon src="resources/android/icon/drawable-hdpi-icon.png" …
Run Code Online (Sandbox Code Playgroud)

android splash-screen cordova ionic-framework

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

GraphQL - 仅允许输入类型的某些值

我正在使用[graphql][1]gem构建一个GraphQL API.

在定义输入时,例如 -

Inputs::BranchInput = GraphQL::InputObjectType.define do
  name 'BranchInput'

  argument :scope,                      types.String
end
Run Code Online (Sandbox Code Playgroud)

该参数scope实际上是一个enum字段,它将接受small或者big.如何在输入中定义此参数只接受这两个值?是否有可能在生成文档时在文档中显示此内容,以便UI开发人员也清楚这一点?

当使用Grape生成REST API时,我通常会使用values参数来定义这样的东西.

ruby-on-rails graphql graphql-ruby

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

Money-Rails Gem:模型中的Humanized_money

在我的捐赠模型中,我已将amount_cents列货币化

我需要模型中捐赠金额的人性化版本(例如643.50),这样我就可以生成并向捐赠者发送PDF收据.

我尝试过humanized_money(self.amount)和self.amount.humanized_money,但是得到了错误:

NoMethodError: undefined method `humanized_money' for #<Donation:0x007fa687ebb678>
Run Code Online (Sandbox Code Playgroud)

如何在模型中获得这种人性化的形式?

class Donation < ActiveRecord::Base
  belongs_to :donatable, polymorphic: true
  belongs_to :added_by_user, foreign_key: "added_by", class_name: "User"

  store_accessor :details, :method

  monetize :amount_cents

  def donations_this_week(branch_id)
    sum =  Donation.sum(:amount_cents).to_money
    return humanized_money(sum)
  end

  def receipt
    Receipts::Receipt.new(
        id: id,
        product: "GoRails",
        message: "This receipt is to acknowledge that we have received a donation with the below details from #{self.donatable.name}",
        company: {
            name: self.donatable.branch.organization.name,
            address: "#{self.donatable.branch.address_line_1}\n#{self.donatable.branch.address_line_2}\n#{self.donatable.branch.email}\n#{self.donatable.branch.legal_details}",
            email: self.donatable.branch.email,
            logo: self.donatable.branch.organization.logo.url(:medium),
        },
        line_items: [
            ["Date",           created_at.to_s],
            ["Donor Name", self.donatable.name], …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails rails-activerecord money-rails

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

Elasticsearch-rails中处于同一级别的多个聚合

我正在尝试使用elasticsearch-rails和elasticsearch-model gem在ElasticSearch的同一级别上执行多个聚合。

在我生成的查询哈希中,有以下内容-

    def query_hash(params, current_person = nil, manager_id = nil)
      aggs = {}
      aggs[:home_country_id] = {terms: {field: "home_country_id"}}
      aggs[:home_region_id] = {terms: {field: "home_region_id"}}
      {
        sort: [ { created_at: { order: "desc" } }, id: { order: "desc" } ],
        aggs: aggs
      }
    end
Run Code Online (Sandbox Code Playgroud)

我存储在对象es_response中的响应。

当我搜索两个聚合时,我只能在响应中找到最后一个。

es_response.response [“ aggregrations”]仅具有最新聚合对象的响应home_region_id

尽管有很多关于嵌套聚合的信息,但是我在《 ES参考》上找不到太多关于在同一级别上构造多个聚合的文档。

我怎样才能解决这个问题?

我的ES版本是5.1

ruby-on-rails elasticsearch elasticsearch-rails

5
推荐指数
0
解决办法
327
查看次数

针对Javascript Blob的Ruby rest-client API请求

我正在尝试在Ruby中为此页面中触发的API请求创建一个rest-client请求.(来源)

通过查看页面中的Javascript,我注意到有一个Javascript Blob被创建并且JSON内容被附加到那个,然后以多部分形式提交,并带有以下脚本 -

我尝试使用以下代码用ruby中的rest-client gem模拟这个 -

namespace :materialize do
  task :connect => :environment do
    base_uri = "https://imatsandbox.materialise.net/web-api/cartitems/register"
    request = '{
     "cartItems":[
     {
       "toolID":"d65e1eca-7adf-453d-a3bb-eb051fffb567",
       "MyCartItemReference":"some reference",
       "modelID":"62352bab-d490-410c-851d-bc62e056e82a",
       "modelFileName":"",
       "fileUnits":"mm",
       "fileScaleFactor":"1",
       "materialID":"035f4772-da8a-400b-8be4-2dd344b28ddb",
       "finishID":"bba2bebb-8895-4049-aeb0-ab651cee2597",
       "quantity":"1",
       "xDimMm":"12",
       "yDimMm":"159.94",
       "zDimMm":"12",
       "volumeCm3":"2.0",
       "surfaceCm2":"100.0",
       "iMatAPIPrice": "25.0",
       "mySalesPrice": "26.0",
     }
     ],
     "currency":"EUR"
  }'
File.open('request', 'wb') do |f|
    f.write request
end


  response = RestClient.post base_uri, {:data => request, headers: {:multipart => true, accept: :json}}
  puts response.request
 end
end
Run Code Online (Sandbox Code Playgroud)

我总是得到的反应机构 -

"{\"error\":{\"message\":\"Wrong request body. Check …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails rest-client

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

Rails - 使用 JSON 从控制器返回带有对象的附加属性

这是我的人员控制器中用于创建操作的代码:

def create
  @person = Person.new(person_params)
  @person.branch_id = session[:branch_id]
  @person.added_by = current_user.id
  if @person.save
    respond_to do |format|
      format.json { render json: @person}
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我在我的人模型中有一个方法来获取人的全名:

def full_name
    [self.first_name, self.middle_name, self.last_name].reject(&:blank?).join(" ")
end
Run Code Online (Sandbox Code Playgroud)

当 @person 作为 JSON 对象返回时,将其全名添加到 @person 的最佳方法是什么

attributes controller model ruby-on-rails

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

在 Rails 应用程序中扩展哈希类

我有一个 Rails 应用程序,我需要扩展模块Hash以添加方法 -

class Hash
  def delete_blank
    delete_if{|k, v| v.nil? or (v.instance_of?(Hash) and v.delete_blank.empty?)}
  end
end
Run Code Online (Sandbox Code Playgroud)

我创建了一个名为 hash_extensions.rb 的文件,并将其放置在我的 lib 文件夹中,当然还使用以下行配置了自动加载路径config/application.rb

config.autoload_paths += %W(#{config.root}/lib) 
Run Code Online (Sandbox Code Playgroud)

然而,当我在哈希上调用删除空白方法时,出现以下错误 -

undefined method `delete_blank' for #<Hash:0x000000081ceed8>\nDid you mean?  delete_if
Run Code Online (Sandbox Code Playgroud)

除此之外,我还尝试将其放置require "hash_extensions"在我从中调用delete_blank方法的文件顶部。

我在这里做错了什么或者我可以避免扩展哈希以具有相同的功能吗?

hash ruby-on-rails

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

与 UNION SQL 查询相反

我有 2 张桌子:

interests (storing the interest ID and name)
person_interests(storing the person_id and interest_id)
Run Code Online (Sandbox Code Playgroud)

如何选择特定人未选择的所有兴趣?

我已经尝试了以下 SQL 查询,但仍然没有得到想要的结果

SELECT * 
  FROM interests LEFT JOIN person_interests 
               ON interests.id=person_interests.person_id
 WHERE person_interests.id IS NULL 
   AND person_id=66;
Run Code Online (Sandbox Code Playgroud)

sql postgresql

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