I am trying to render a pdf with wicked pdf in my action.
def show
respond_to do |format|
format.html
format.pdf do
render pdf: "reciept"
end
end
end
This works fine for html format, but gives me
Missing template /reciept with {:locale=>[:en], :formats=>[:pdf], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}.
Installed gem 'wicked_pdf' and 'wkhtmltopdf-binary'.
Using rails 7.
Any help will be appriciated.
I Thought it was issue with gem so reinstalled the gem but nothing changed.
render pdf: "recipt", template: 'pdf/recipt', formats: [:html]
Must tell formats to html if using recipt.html.erb or else it will give missing template error in rails 7. For using .pfd.erb file, without formats work.
Related
When upgraded the rails application from rails 5.0 to rails 5.2 I am getting the following error when I am trying to login using saml
Missing template sso/authsetup/saml, application/saml with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee, :axlsx, :haml, :jbuilder]}. Searched in: * "/home/app/be/app/views/custom/1" * "/home/app/be/app/views" * "/usr/local/bundle/gems/ruby/2.5.0/gems/letter_opener_web-1.4.1/app/views" * "/usr/local/bundle/gems/ruby/2.5.0/bundler/gems/ckeditor-bbc03cf0b757/app/views" * "/usr/local/bundle/gems/ruby/2.5.0/gems/kaminari-core-1.2.2/app/views" * "/usr/local/bundle/gems/ruby/2.5.0/gems/bootstrap5-kaminari-views-0.0.1/app/views"
I am getting this error on this line
render :text => "Omniauth setup phase.", :status => 404
I have gone through a few of the https://github.com/thoughtbot/ember-cli-rails/issues/527 & What to use instead of `render :text` (and `render nothing: true`) in rails 5.1 and later? and try to update this line
render :plain => "Omniauth setup phase.", :status => 404
head :not_found
respond_to do |format|
format.html { head :not_found }
end
But none of it works. Any help is appreciated thanks
After setup a simple API and try to login with a simple session controller
Session Controller
def create
user = User.find_by(email: [:email])
if user && user.authenticate([:password])
render json: {token: user.access_token}, status: 200
else
render text: "Email and password combination are invalid", status: 422
end
end
in the logs show
ActionView::MissingTemplate (Missing template sessions/create,
application/create with {:locale=>[:en], :formats=>[:json],
:variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby,
:jbuilder]}. Searched in: * "/home/daniel/ranks/app/views" ):
after googling around seems a issue with jbuilder and the workaround that some proposed was to: in the application controller
include ActionView::Rendering
def render_to_body(options)
_render_to_body_with_renderer(options) || super
end
but the problem persist so someone has any idea how to solve this issue with rails 5.1 and jbuilder 2.7.0?
I have a controller action that I am trying to only render js from. Here's what I have
def get_script
respond_to :js
render :script
end
I'm using respond_to :js to hopefully force the request to only respond to js. Then I'm calling render :script to load a file called script.js.erb
My request is the following
Completed 500 Internal Server Error in 15ms (ActiveRecord: 0.5ms)
ActionView::MissingTemplate (Missing template widgets/get_script, application/get_script with {:locale=>[:en], :formats=>[:js, :html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder]}. Searched in:
* "/home/jkoehms/TECC/tecc/app/views"
* "/home/jkoehms/.rvm/gems/ruby-2.0.0-p643/gems/devise-3.5.1/app/views"
)
So there are two problems here. Although the request is processed as JS, the render is looking for js or html as indicated in the formats section. Secondly, the render is looking for get_script.js.erb when it should be looking for script.js.erb. I used the following documentation as a resource for rendering: Layouts and Rendering
Question:
1.) Does the respond_to :js do what I'm hoping it to do, or do I have to put it in a do |format| block?
2.) Why isn't render :script looking for script.js.erb?
Have you tried this inside your view?
render "widgets/script.js.erb", format: :js
Missing template events/index, application/index with {:locale=>[:en], :formats=>[:pdf], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :haml]}. Searched in: * "c:/Put/Team/project/app/views" * "c:/Put/Team/project/vendor/bundle/ruby/2.0.0/gems/browserlog-0.0.2/app/views" * "c:/Put/Team/project/vendor/bundle/ruby/2.0.0/gems/devise-3.4.1/app/views"
Here is the error I encounter when I'm trying to create a pdf from the ruby application I have made. This error occurs when I put .pdf on the end of my URL.
This is the code I've implemented in my app controller file
def show
#event = current_user.events.find(params[:id])
respond_to do |format|
format.html
format.pdf do
pdf.text = Prawn::Document.new
pdf.text "Hello World"
send_data pdf.render
end
end
end
It wants to render a template in your views, so my guess it's not recognizing your PDF render statement. It is odd that the pointer is to events/index while you're saying the source is the show method.
Try referring to this StackOverflow thread:
How to render format in pdf in rails
Make sure you name your view to "show.pdf".
Trying to get User model to print to JSON, tried making a file with a json.rabl extension as follows:
file.json.rabl
object #users
attributes :id, :name
When I try to view this, I get the following error message:
Missing template users/autocomplete, application/autocomplete with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee, :rabl, :rb]}.
However, if I rename the file to file.rabl, it renders the JSON, but in an HTML page instead. How do I get it to print a pure JSON file?
Here is my controller code for the file view:
def file
#users = User.all
respond_to do |format|
format.html
format.json
end
Just had to add .json to the URL.