My set up : Rails 4.1.1 and ruby 2.1.1p76 locally on MacOS X 10.10.1 and prod on Heroku.
I installed gem 'wicked_pdf'and gem 'wkhtmltopdf-binary'
In config/initializers/mime_types.rb, I added :
Mime::Type.register "application/pdf", :pdf
In config/initializers/wicked_pdf.rb, I tried both :
:exe_path => '/usr/local/bin/wkhtmltopdf'
and
:exe_path => '#{Rails.root}/bin/wkhtmltopdf'
When I run in Terminal
$ wkhtmltopdf http://google.com google.pdf
from my app directory, it does generate a pdf file. So I assume wkhtmltopdf is set up properly.
My object_controller.erb contains :
def print_view
@teams = [Team.find(params[:team_id])]
respond_to do |format|
format.html
format.pdf do
render :pdf => "file_name",
:layout => "/layouts/print_layout.html.erb"
end
end
end
My views/layouts/print_layout.html.erb (shorten for clarity) :
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<%= wicked_pdf_stylesheet_link_tag('print', :media => :print) %>
</head>
<body class="<%= controller_name %> <%= action_name%>">
<%= yield %>
</body>
</html>
And my views/object/print_view.html.erb (shorten for clarity) :
<div id="schedule-tables">
<%= render 'weekview_print' %>
</div>
I have 2 problems :
- I get a html page, not a pdf
- the page is using the default layout, not the specified layout