.docxファイルをHTMLテンプレートから作成する必要があります。htmltoword gemを使用しました。RoR HTMLテンプレートから.docx
使用法:私のに
get 'preview' => 'foo#preview'
そして:
gem 'htmltoword', '~> 0.5.1' #last version of the gem
私はルートを置く(route.rb):私は宝石(Gemfile)を加え
bar.html.erb私はそのURLをターゲットとするリンクを持っています:<%= link_to '.docx', preview_path %>
テンプレート(preview.docx.erb):
<h1>foobar</h1>
コントローラで
( foos_controller.rb):ただしclass FoosController < ApplicationController
respond_to :docx
#other code
def preview
respond_to do |format|
format.docx do
render docx: 'foobar', filename: 'preview.docx'
end
end
end
end
、Iエラーが発生しました:
ActionController::UnknownFormat
このエラーを解決するにはどうすればよいですか?
マイ設定:
RoRのv4.2.4
Rubyは
Also, there is an open github issue for this/similar topicをv2.2.3p173。
更新:@kajalojhaが述べたように、respond_with/Class-Level respond_to
は個々の宝石に削除されているので、私installed the responders gemは、しかし、私は同じエラーを取得します。
どの宝石を使用するかおすすめできますか? – Vucko
フォーマッタ宝石.. –
私はそれを見つけようとしていますが、運がありません。リンクを投稿できますか? – Vucko