Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActionController::UnknownFormat #47

Open
ghost opened this issue Apr 19, 2016 · 4 comments
Open

ActionController::UnknownFormat #47

ghost opened this issue Apr 19, 2016 · 4 comments

Comments

@ghost
Copy link

ghost commented Apr 19, 2016

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:

respond_to :docx

def testcycle_requirement_document
  respond_to do |format|
    format.docx do
      render docx: 'requirement_document', filename: 'my_file.docx'
    end
  end
end

I am using htmltoword (0.5.1)

Kindly help.

@lwnhp
Copy link

lwnhp commented May 2, 2016

I'm experiencing the exact same issue. Any clues so far?

@adelivuk-zz
Copy link

adelivuk-zz commented May 11, 2016

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

foos_controller.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.

@rvanrinsum
Copy link

rvanrinsum commented Jul 7, 2016

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

@lukelex
Copy link

lukelex commented Mar 22, 2018

@ghost does @rvanrinsum's solution work for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants