2014-03-13 46 views
0

我已閱讀'ruby-rtf'的文檔。如何在Rails應用程序中使用ruby-rtf導出RTF文件?

我不清楚如何將這與我的控制器集成。我也做了以下內容:

  1. gem install ruby-rtf
  2. 插入到配置/初始化/ 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 
+0

你的寶石添加到您的Gemfile?也許它也需要在控制器的最上方有一個'require'RTF''。 – KappaNossi

+0

我已經添加到Gemfile中:gem'ruby-rtf',我向控制器添加了require'RTF',並且出現以下錯誤:無法加載此文件 - RTF – Venomoustoad

回答

0

上面的說明是正確的,我在寶石安裝中犯了一個錯誤。

的寶石必須

gem 'rtf' 

和控制器需要線

require 'rtf' 
相關問題