Wicked_PDF changing filename according to id
-
06-02-2021 - |
Question
I am using wicked_pdf in rails3. No problem generating pdf or saving them. My only issue is I want to dynamically name the files according to the @post.id. When I put the following code my file comes out being named #{@post.id}. What am I doing wrong. Thanks
def show
@post = Post.find(params[:id])
render :pdf => '#{@post.id}',
:layout => 'layouts/layout1.html.erb',
:template => 'posts/show.html.erb',
:save_to_file => Rails.root.join('public','pdfs', '#{@post.id}' + ".pdf")
end
Solution
interpolation only works if you use DOUBLE QUOTES.
just do "#{@post.id}"
and you're all set
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow