小编MrW*_*ter的帖子

将数字签名插入现有的pdf文件中

我需要使用rails应用程序服务器将数字签名插入到现有的pdf文件中.(基本上,客户端上传pdf文件,服务器使用本地证书对其进行签名)

我一直在使用JSignpdf将数字签名插入到pdf文件中,并开始探索ruby的宝石......

我在rubypdf网站http://soft.rubypdf.com/software/pdf-digital-signe上找到了另一个可移植文件,但在ruby中找不到任何宝石甚至示例代码.

我还看了OpenSSL的数字签名验证,但无法理解如何使用本地证书文件对现有文档进行实际签名.

我还在http://code.google.com/p/origami-pdf/上达到了一个高峰,但对于一个假设"简单"(至少在概念上)的任务来说,这似乎有点苛刻.

有什么想法/建议吗?

谢谢

ruby pdf digital-signature

11
推荐指数
1
解决办法
8048
查看次数

如何在rails中添加条件where子句

我是一个铁杆新手,我正试图在带有rails的桌子上进行搜索,而我只是使用我的sql知识来做到这一点.但这似乎不像铁路或红宝石甚至......

有没有更好的方法来做我在下面做的事情?(基本上,只有在填充时才将日期参数传递给sql)

def search(begin_date=nil, end_date=nil)

    subject = " and created_at "

    if !(begin_date.nil? || end_date.nil?)
      where_part = subject + "BETWEEN :begin_date AND :end_date"
    else if (begin_date.nil? && end_date.nil?) 
      where_part = ""
    else if(begin_date.nil?)
      where_part = subject + " <= :end_date"
    else if (end_date.nil?)
      where_part = subject + " >= :begin_date"
    end
    end
    end
    end

    User.joins(places: {containers: {label: :user}}).where("users.id= :user_id "+where_part, user_id: self.id, begin_date:begin_date, end_date:end_date).group(...).select(...)
end
Run Code Online (Sandbox Code Playgroud)

编辑

user.rb

has_many :containers
has_many :user_places
has_many :places, through: :user_places
has_many :labels
Run Code Online (Sandbox Code Playgroud)

place.rb

has_many :containers …
Run Code Online (Sandbox Code Playgroud)

ruby sql conditional ruby-on-rails rails-activerecord

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

使用JSON请求和RestSharp通过c#上传文件

在管理通过c#将数据加载到我的Rails服务器之后(请点击此处了解我在说什么),我现在正尝试将文件上传到同一台服务器以及其他数据.

在Ruby中,我可以使用代码执行此操作:

require 'HTTMultiParty'

    class ReceiptCreate
        include HTTMultiParty
        # Log to file
        # debug_output File.new("httparty1.log", "w+")
        base_uri "localhost:3000"
        format :json
        headers "Accept" => "application/json"

      def initialize
      end

      def post(machine_serial,filepath,tag_number,token)
        options = { body: 
                    {receipt:
                        {tag_number:tag_number,
                         receipt_file: File.new(filepath),
                         ispaperduplicate:0
                         },
                    machine:
                        {serial_number: machine_serial,
                         safe_token: token
                         }
                    }               
                }
        self.class.post('/receipts', options)
      end
    end

receipt = ReceiptCreate.new()
filename1 = "C:\\filename1.pdf"
filename2 = "C:\\filename2.pdf"
response=receipt.post("2803433",filename2,"p94tt7w","123")
puts response
Run Code Online (Sandbox Code Playgroud)

当我检查rails服务器上的参数时,我看到了

Parameters: {"receipt"=>{"tag_number"=>"p94tt7w", "receipt_file"=>#<ActionDispatch::Http::UploadedFile:0x4183ea8 @original_filename="Invoice.pdf", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"receipt[receipt_file]\"; filename=\"Invoice.pdf\"\r\nContent-Length: 11653\r\nContent-Type: application/octet-stream\r\nContent-Transfer-Encoding: binary\r\n", @tempfile=#<File:C:/Users/diogo/AppData/Local/Temp/RackMultipart20130103-18168-efiqia>>, "ispaperduplicate"=>"0"}, …
Run Code Online (Sandbox Code Playgroud)

c# ruby json file-upload

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

按年龄范围分组用户在ruby中

我正在尝试按年龄范围列出用户数量:

Range  : #Users
10-14  : 16
15-21  : 120
22-29  : 312
30-40  : 12131
41-70  : 612
71-120 : 20
Run Code Online (Sandbox Code Playgroud)

我在考虑创建一个静态的哈希数组:

AGE_RANGES = [
  {label:"10 - 14", min:10, max:14},
  {label:"15 - 21", min:15, max:21},
  {label:"22 - 29", min:22, max:29},
  {label:"30 - 40", min:30, max:40},
  {label:"41 - 70", min:41, max:70},
  {label:"71 - 120", min:71, max:120}
]
Run Code Online (Sandbox Code Playgroud)

然后将其用于我的搜索过滤器以及我的查询.但是,我想不出能从中获得最大性能的方法.

我的模型中的方法仅按年龄分组:

def self.group_by_ageRange(minAge, maxAge)

  query = User.group("users.age")
              .where("users.age BETWEEN minAge and maxAge ")
              .select("users.age,
                        count(*) as number_of_users")

end
Run Code Online (Sandbox Code Playgroud)

有什么建议?

ruby activerecord group-by ruby-on-rails range

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

如何将参数发送到回形针处理器

我试图了解如何将模型值发送到回形针自定义处理器中,但无法弄清楚为什么它如此困难,或者解决方案可能是什么,因为我现在正在尝试解决这个问题几天...这是我的代码,从我的模型和处理器中提取。

从我的模型来看:

...
  has_attached_file :receipt_file,
                    :storage => :s3,
                    :s3_credentials => "#{Rails.root}/config/s3.yml",
                    :path => "/:style/:id/:filename",
                    :s3_protocol => "https",
                    :styles => { :text => { style: :original, receipt_id: self.id }},
                    processors: [:LearnProcessor]
...
Run Code Online (Sandbox Code Playgroud)

为什么我不能使用“self.id”来获取收据 ID ?它是如何"/:style/:id/:filename"被翻译成类似/original/1/abc.pdf, 如果我输入receipt_id: :id, 我得到的只是options[:receipt_id](见下文):id而不是1

我需要某种插值吗?

处理器代码

module Paperclip

    class LearnProcessor < Processor
      attr_accessor :receipt_id,:style


      def initialize(file, options = {}, attachment = nil)
        @file           = file
        @current_format = File.extname(@file.path)
        @basename       = File.basename(@file.path, @current_format)
        @style = options[:style] …
Run Code Online (Sandbox Code Playgroud)

ruby arguments ruby-on-rails processor paperclip

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

C#在JSON字符串的开头和结尾添加双引号会导致服务器解码错误

我正在编写ac#机制,使用Json将文件上传到Rails服务器.

在进入文件部分之前,我只是想发布到服务器,并且似乎在到达服务器的json字符串有一些问题.

我可能做错了什么?我已经尝试了两种不同的序列化字符串的方法,甚至加载已经序列化的字符串......

我想知道它是否与字符串的开头和结尾的双引号有关,显然是发送到服务器,以及如何从请求中删除它们(没有周围的引号和使用WizTools.org的RestClient,这一切都进行了很好......):

MultiJson::DecodeError (757: unexpected token at '"{\"receipt\":{\"total\":100.0,\"tag_number\":\"xxxxx\",\"ispaperduplicate\":true},\"machine\":{\"serial_number\":\"111111\",\"safe_token\":\"1Y321a\"}}"')
Run Code Online (Sandbox Code Playgroud)

我的c#代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RestSharp;
using System.Web.Script.Serialization;
using Newtonsoft.Json;

namespace RonRestClient
{


    class templateRequest
    {
        public Receipt receipt;
        public class Receipt
        {
            public float total;
            public String tag_number;
            public bool ispaperduplicate = true;
            public Receipt(float total, String tagnr)
            {
                this.total = total;
                this.tag_number = tagnr;
            }
        };
        public Machine machine;
        public class Machine
        {
            public String …
Run Code Online (Sandbox Code Playgroud)

c# serialization json

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

如何增加 Heroku 30s h12 超时

我正在运行一个 rails 应用程序,它有一个来自用 C++ 开发的本地客户端的 json webservice 调用(一个带有多部分 json 表单的 post 命令,上传一个流文件)

我已经在 Heroku 文档上阅读了关于路由网格的内容,提到了 http 连接的 30 秒 Heroku 限制,以及关于长轮询替代方案,指的是工作人员 dynos。

在通话期间,我处理 pdf 文档并在其中插入签名。这个 pdf 文件可以是 100kb 或 11Mb(或者更多)。

我知道我最终必须在后台进程上执行此操作,但我想在绝对必要之前避免这样做。

你知道有什么方法可以增加这个超时吗?

正如您在下面的代码中看到的那样,我正在保存文档后对其进行处理(我在after_save.

我非常希望客户端在文档处理之前得到响应,但我仍然在 heroku 端超时,在我的客户端出现错误。

对于较小的文档,这一切都很好,但是对于只有 400kb 的 121 页 pdf 文档,它会爆炸..

最后,我的文件被上传了,所以我需要的是在超时响应被发送之前让该响应继续到我的客户端应用程序......

有什么建议?

我的错误:

 at=error code=H12 desc="Request timeout" method=POST path=/documents host=fierce-beach-2720.herokuapp.com fwd="81.193.155.217/bl4-155-217.dsl.telepac.pt" dyno=web.1 queue=0ms wait=0ms connect=1ms service=32272ms status=503 bytes=0
Run Code Online (Sandbox Code Playgroud)

我的控制器:

respond_to do |format|
      if @document.save!
        format.html { redirect_to root_path, :flash => { …
Run Code Online (Sandbox Code Playgroud)

timeout ruby-on-rails heroku

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

Params变量没有填充JSON帖子数据....为什么?

我之前使用过这个服务,还有其他一些领域,但是现在我似乎没有让它工作,并且我不太明白为什么.

我将以下json发布到我的Rails应用程序(使用RestClient 2.4,用于测试):

{
    "camp":{
        "total": 100,
        "number": "epw1f6e"
    },
    "machine":{
        "serial_number": "1234567",
        "token": "fONxDN"
    }
}
Run Code Online (Sandbox Code Playgroud)

营地控制员:

def create
    if is_it_json?
      logger.debug params.inspect
      machine = Machine.find_by_serial_number(params[:machine][:serial_number])
...
Run Code Online (Sandbox Code Playgroud)

从记录器中,我得到的参数是:{"action"=>"create","controller"=>"camp"}

json信息在哪里?

我的日志错误:

Started POST "/camps" for 127.0.0.1 at 2012-07-15 00:08:21 +0100
Processing by CampsController#create as JSON
WARNING: Can't verify CSRF token authenticity
{"action"=>"create", "controller"=>"camps"}
Completed 500 Internal Server Error in 2ms

NoMethodError (undefined method `[]' for nil:NilClass):
  app/controllers/camps_controller.rb:24:in `create'
Run Code Online (Sandbox Code Playgroud)

我可能做错了什么?

谢谢

rest json ruby-on-rails params

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