How to fix a missing template error?
If @announcement
fails to save in AnnouncementsController#create
, you render the default view for the action - in this case create.html.erb
which doesn't exist. Thus, you get the error you're seeing.
Usually, the create action would re-render the template with the form. Usually that's the new
action, which would mean adding render "new"
to the else
part of your create
action.
In your case however, it seems like it's in the "shared/announcements_form"
partial, which would mean adding
render "shared/announcements_form"
to your create
action.
Template is missing
This error happens if you don't redirect in the create
method of your controller.
Are you redirecting in the create method in the controller or rendering the new form, in case of error?
Without the redirection in the create method in the controller, you need to make a new file called create.html.erb
. Usually, after successful creation, you redirect to some other page like shown below
def create
# some object you want to create
# if the object.save is fine
# redirect_to object
# else
# render new with the errors
# end
end
getting Missing Template error while creating a new user
I think you need to add else part to handle when user is not saved
def create
@user = User.new(new_params)
if @user.save
redirect_to admin_home_user_panel_path
else
#do render or redirect_to
end
end
Rails4: Template is missing error with PDFKit
The reason you are getting Missing template /show
is because from the controller using template: "show"
isn't specific enough for rails to know where in your views folder to find the show
file.
You can see the evidence of this in your error where it says it searched for show
inside ../app/views
. You need to use the template parent folder along with the template name.
change this
format.pdf do
html = render_to_string template: "show"
...
end
to this
format.pdf do
html = render_to_string template: "schedules/show.html.erb"
...
end
Template is missing in Rails
Your template would need to be inside of /views/application
for the convention to work.
Rails looks inside of /views/CONTROLLER/action
by convention without specifying a specific location.
/views/application/startpage.html.erb
should work in your situation.
Bonus learning points:
A common practice I see for creating normal, static pages, is a PagesController
which handles each of them. Doing this, your route would point to pages#startpage
and your view would be inside of /views/pages/startpage.html.erb
-- Just a tip!
Rails Template is Missing Error
Notice how your controller action and your error says pages/show_admin_panel
(with underscores) but your view is called pages/adminpanel.html.erb
(no underscores and no "show" part in the beginning).
Ruby on Rails Template is missing Error
The name of your template file should be "settings.html.erb". You're missing an "e" in the file extension.
Note the part of the error where it says :handlers=>[:rxml, :erb, :builder, :rjs, :rhtml]
. The file extension of your view must be one of these for the template to be processed.
Ruby on Rails - template missing error
It seems like your project path for your rails app has has a folder with square brackets in the name (the folder titled Rails [Ruby]
) :
/Users/Constantin/Development/Rails [Ruby]/new-app/app/views
Remove the square brackets from the folder name and restart your server.
For more information, check out this issue: Rails projects do not work if project path contains open bracket "["
Also change your get
route to be like this:
get 'welcome/index' => 'welcome#index'
Related Topics
How to Sort a Ruby Array by Two Conditions
Encrypt Data Bag from Inside of Ruby Without Relying on Knife
Differencebetween Def Func(Var) and Def Func=(Var)
Define a Class Method in a Module
Ruby Selenium Web Drive: How to Find Specific Element by Xpath Div Id and CSS Class
How to Remove Devise Password Resetting During Email Confirmation
Fetching Second Row from CSV File in Ruby
How to Remove the Extra Double Quote
Login Session Data Not Persisting in Rails 6
How to Verify Pacts Against an API That Requires an Auth Token
Illegal Quoting in Line 1 Using Ruby CSV
How to Render the Ajax Response in Rails
How to Convert a Formatted String into Plain Text