Open ghost opened 8 years ago
I'm experiencing the exact same issue. Any clues so far?
I had the same issue and I've posted this question on SO - [RoR HTML template to .docx](http://stackoverflow.com/questions/37161214/ror-html-template-to-docx/37165372], and I've managed to solve it. From SO).
Note for RoR versions 4.2. : respond_with / Class-Level respond_to
has been removed to an individual gem, so you need to install the responders gem.
Let's create a download
logic.
Gemfile
gem 'responders'
gem 'htmltoword', '~> 0.5.1'
routes.rb
get 'download' => 'foos#download', format: 'docx' #added format
_fooscontroller.rb
class FoosController < ApplicationController
respond_to :docx
def download
@bar = "Lorem Ipsum"
respond_to do |format|
format.docx do
# docx - the docx template that you'll use
# filename - the name of the created docx file
render docx: 'download', filename: 'bar.docx'
end
end
end
end
download.docx.erb
<p><%= @bar %></p>
And I've added some link to trigger the download logic:
<%= link_to 'Download bar.docx', foo_download_path %>
Which will download the bar.docx
file with "Lorem Ipsum" in it.
Had the same problem. I wrote the line in routes.rb like this:
routes.rb
get :export, defaults: { format: :docx }
and I didn't need the responders gem. also, I didn't need the respond_to :docx
in the controller
@ghost does @rvanrinsum's solution work for you?
Hi,
I am unable to view the docx file, as every time I go and try accessing the routes, it throws error
ActionController::UnknownFormat (ActionController::UnknownFormat): app/controllers/enterprisecycles_controller.rb:22:in `testcycle_requirement_document'
respond_to do |format| format.docx do
I have written following code:
I am using htmltoword (0.5.1)
Kindly help.