【问题标题】:How do I export RTF file using ruby-rtf in a rails app?如何在 Rails 应用程序中使用 ruby​​-rtf 导出 RTF 文件?
【发布时间】:2014-03-14 08:25:45
【问题描述】:

我已经浏览了“ruby-rtf”的文档。

我不太清楚如何将它与我的控制器集成。我做了以下事情:

  1. gem install ruby-rtf
  2. 插入 config/initializers/mime_types.rb

     Mime::Type.register "text/richtext", :rtf
    
  3. 我的视图有一个导出按钮,可以路由到以下控制器操作。这是我的控制器文件:

    def export_file
    
        document = RTF::Document.new(RTF::Font.new(RTF::Font::ROMAN, 'Times New Roman'))
        document.paragraph do |p|
           p << "This is the first sentence in the paragraph. "
           p << "This is the second sentence in the paragraph. "
           p << "And this is the third sentence in the paragraph."
        end
        send_file document, :type=>"text/richtext"
    end
    

我收到以下错误,我做错了什么?

uninitialized constant JobVacanciesController::RTF

【问题讨论】:

  • 您是否将 gem 添加到您的 Gemfile 中?也许它还需要在控制器的最顶部有一个require 'RTF'
  • 我已添加到 Gemfile : gem 'ruby-rtf' ,我将 require'RTF' 添加到控制器中,但出现以下错误:无法加载此类文件 -- RTF

标签: ruby-on-rails ruby ruby-on-rails-3


【解决方案1】:

上面的说明是正确的,我在gem安装时出错了。

宝石需要

gem 'rtf'

控制器需要线路

require 'rtf'

【讨论】:

    猜你喜欢
    • 2015-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-21
    • 1970-01-01
    • 2011-01-18
    相关资源
    最近更新 更多