We use exception_notification gem in our project and we're seeing missing template errors now. Here's what our setup looks like:
# Gemfile
gem 'exception_notification'
# config/initializers/exception_notifications.rb
if Rails.env.production?
server_hostname = `hostname`.chomp
Rails.application.config.middleware.use ExceptionNotifier,
:exception_recipients => %w(webdev#domain.com),
:sender_address => %("Application Error" <admin#domain.com>),
:email_prefix => "[#{server_hostname}] "
end
When the exception occurs, we do indeed receive the email, but the rendered error page is an unstyled mix of raw ERB and text, not pretty at all <screenshot> and the error message in our log is:
ActionView::MissingTemplate (Missing template /exception_notification with {:locale=>[:en], :formats=>[:text], :handlers=>[:erb, :builder]}. Searched in:
* "/Users/j/Projects/agilebits/app/views"
* "/Users/j/Projects/agilebits/vendor/bundle/ruby/1.9.1/gems/exception_notification-3.0.1/lib/exception_notifier/views"
):
Of course, the views are not in my app/views folder, but in the gems folder I do have:
↪ ls -R /Users/j/Projects/agilebits/vendor/bundle/ruby/1.9.1/gems/exception_notification-3.0.1/lib/exception_notifier/views
exception_notifier
/Users/j/Projects/agilebits/vendor/bundle/ruby/1.9.1/gems/exception_notification-3.0.1/lib/exception_notifier/views/exception_notifier:
_backtrace.html.erb _request.html.erb background_exception_notification.html.erb
_backtrace.text.erb _request.text.erb background_exception_notification.text.erb
_data.html.erb _session.html.erb exception_notification.html.erb
_data.text.erb _session.text.erb exception_notification.text.erb
_environment.html.erb _title.html.erb
_environment.text.erb _title.text.erb
Looks like Rails is looking for the view /exception_notification.text.erb in exception_notification-3.0.1/lib/exception_notifier/views and not in the exception_notifier subdirectory there. At this point, I'm not sure if this is a problem with Rails or the exception_notification gem, but given that the emails are sent, I'm not sure why there's an error message at all.
Thanks for taking a look and for any guidance.
I had the same issue and ended up forking exception_notification and changing where it looks for the templates in notifier.rb. Fork is at https://github.com/etcetc/exception_notification
Related
I've been trying to launch my project https://github.com/robdrosenberg/news-hunt on Heroku the last couple days and heroku won't serve my public/index.html page.
Here is the error I'm currently getting:
ActionController::RoutingError (No route matches [GET] "/")
This error has been brought up all over StackOverflow and I've tried as many of those solutions as I could.
For example, routing to the file directly through a welcome controller gives me an error as well
Routes
Rails.application.routes.draw do
post 'user_token' => 'user_token#create'
post 'users' => 'users#create'
namespace :api do
get 'reddit' => 'posts#reddit'
get 'producthunt' => 'posts#producthunt'
get 'medium' => 'posts#medium'
get 'hackernews' => 'posts#hackernews'
get 'githubtrending' => 'posts#githubtrending'
get 'all' => 'posts#all'
get 'bookmarks' => 'bookmarks#index'
post 'bookmarks' => 'bookmarks#create'
delete 'bookmarks' => 'bookmarks#destroy'
end
root 'welcome#index'
end
Controller
class WelcomeController < ApplicationController
def index
render file: Rails.root.join('public','index.html')
end
end
Error
ActionView::MissingTemplate (Missing template public/index.html with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}. Searched in: app/app/views
Changing config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? to = true hasn't made a difference.
I've tried using redirects which result in the app crashing from too many redirects.
What I find odd is when I try to render the file directly it searches in the app/views folder. Everything works fine locally, so it has to be something with the production environment and Heroku.
I'm using Rails in API mode and using Vue through CDN in my index.html file.
I deployed a different project the same way and had no issues. You can find that codebase here: https://github.com/robdrosenberg/commitment-ledger.
Any help is greatly appreciated!
You don’t actually have a public/index.html page in that repo, but rather a public/Index.html (note the case of the ‘i’ and ‘I’). This won’t make much difference if you’re developing on Windows or Mac, but on Linux (which is used on Heroku) they will be treated as different files.
Rename the file to index.html (use git mv and don’t forget to commit) and it should work.
Is there a reason you want to redirect to public/index? Of course, I don't know your application, so this may not be helpful. Have you considered moving your index.html file to the views/welcome directory? This is the default location that the welcome#index method will render a file from.
Try adding this to your config/routes.rb file:
get '', to: redirect('/Index.html')
That way the requests to the application root will redirect to the index file in the public folder.
As mentioned below you have named the file with a capital ‘I’, you will need to use the same case when referencing it in the redirect above, as updated.
We are upgrading from Rails 4.2.5 to 5.0.0.beta1
When testing we expected to see index views rendered with paginated links as before.
But we now get an ArgumentError error page, for example:
ArgumentError in Transactions#index
/app/views/kaminari/_paginator.html.erb where line #10 raised:
<%= paginator.render do -%>
Generating an URL from non sanitized request parameters is insecure!
Application Trace | Framework Trace | Full Trace
app/views/kaminari/_paginator.html.erb:10:in block in _app_views_kaminari__paginator_html_erb___4026289994022119719_69904100316060' app/views/kaminari/_paginator.html.erb:9:in_app_views_kaminari__paginator_html_erb___4026289994022119719_69904100316060'
app/views/transactions/index.html.erb:2:in `_app_views_transactions_index_html_erb__422882858554400818_60602560'
An issue has been raised with kaminari
On further investigation here is the new Rails 5.0.0.beta1 code that now throws the error:
Adding this to config/application.rb 'fixes' it, but not a great idea:
config.action_controller.permit_all_parameters = true
Instead adding this does not fix the issue, not sure why:
config.action_controller.always_permitted_parameters = [:current_page, :page, :total_pages, :per_page, :remote, :paginator]
This appears to be fixed in the github master branch, so for now in your gem file specify:
gem 'kaminari', :git => "git://github.com/amatsuda/kaminari.git", :branch => 'master'
I forked a gem and changed some things, but I am really desperate. I always get Template is missing:
Template is missing
Missing template spree/addresses/index, spree/store/index, spree/base/index, application/index with {:locale=>[:de, :en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee, :haml, :rabl], :versions=>[:v1]}. Searched in: * "/Users/Manu/Documents/rails_projects/my_store_dev/app/views" * "/Users/Manu/.rvm/gems/ruby-2.1.2/bundler/gems/spree_my_favourites-6076d6ee5cb2/app/views" * "/Users/Manu/.rvm/gems/ruby-2.1.2/bundler/gems/spree_address_book-b66e2abf6429/app/views" * "/Users/Manu/.rvm/gems/ruby-2.1.2/bundler/gems/spree-promotion-roles-rule-0fd33e96c5c4/app/views" * "/Users/Manu/.rvm/gems/ruby-2.1.2/bundler/gems/spree-promotion-exclude-specials-rule-1debc9765387/app/views" * "/Users/Manu/.rvm/gems/ruby-2.1.2/bundler/gems/spree_better_terms_and_conditions-8001a85040eb/app/views" * "/Users/Manu/.rvm/gems/ruby-2.1.2/gems/spree_quick_cart-2.2.3/app/views" * "/Users/Manu/.rvm/gems/ruby-2.1.2/bundler/gems/spree_i18n-1d94e07c68c7/app/views" * "/Users/Manu/.rvm/gems/ruby-2.1.2/bundler/gems/spree_auth_devise-01901766a256/lib/views/backend" * "/Users/Manu/.rvm/gems/ruby-2.1.2/bundler/gems/spree_auth_devise-01901766a256/lib/views/frontend" * "/Users/Manu/.rvm/gems/ruby-2.1.2/gems/devise-3.2.4/app/views" * "/Users/Manu/.rvm/gems/ruby-2.1.2/bundler/gems/spree_gateway-5cbe3890d1a0/app/views" * "/Users/Manu/.rvm/gems/ruby-2.1.2/bundler/gems/spree-33c8fa4d51d8/frontend/app/views" * "/Users/Manu/.rvm/gems/ruby-2.1.2/bundler/gems/spree-33c8fa4d51d8/backend/app/views" * "/Users/Manu/.rvm/gems/ruby-2.1.2/bundler/gems/spree-33c8fa4d51d8/api/app/views" * "/Users/Manu/.rvm/gems/ruby-2.1.2/bundler/gems/spree-33c8fa4d51d8/core/app/views" * "/Users/Manu/.rvm/gems/ruby-2.1.2/gems/kaminari-0.15.1/app/views"
This is my routes file:
Spree::Core::Engine.routes.draw do
# Add your extension routes here
namespace :account do
resources :orders, only: [:index]
resources :favourites, only: [:index]
resources :addresses, only: [:index]
end
end
This is my AddressesController in controller/spree/account/:
module Spree
module Account
class AddressesController < Spree::StoreController
before_filter :check_logged_in_user
def index
#user = try_spree_current_user
end
private
def check_logged_in_user
unless try_spree_current_user
account_addresses__path
redirect_to spree_login_path
end
end
end
end
end
I have a index.haml in views/spree/account/addresses/, and this is part of rake routes:
account_orders GET /account/orders(.:format) spree/account/orders#index
account_favourites GET /account/favourites(.:format) spree/account/favourites#index
account_addresses GET /account/addresses(.:format) spree/account/addresses#index
Can someone please give me a hint?
I had an similar experience, not sure if this applies to you or not but here it is:
This is the error I got:
ActionView::MissingTemplate at / .
Missing partial spree/shared/_google_analytics with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee, :haml, :jbuilder, :rabl], :versions=>[:v1]}. Searched in:
* "/Users/sjones/work/cs-spree/app/views"...
But it turns out the partial actually exists and is even being parsed and run (I use the RubyMine debugger to check)
The error is incorrect. In my case a helper method try_spree_current_user was missing from the controller, and this missing method NoMethodError error was somehow being trapped and replaced with the MissingTemplate error shown.
Fixing that error caused the template to load just fine.
Like I said, this may not be your problem, but this is so weird I'm posting this for others.
I was getting this error after installing extension spree_theme
Missing partial spree/shared/_google_analytics
i ended up finding the file (so it was not missing at all) here: public/vinsol_spree_themes/current/views/spree/shared/_google_analytics.js.erb
after debugging a bit finally detected a missing class of class not defined type error with something Spree::Tracker so all i had to was to fix that dependency and the thing worked, as mentioned above by stujo sometimes it seems this message is not related with the file itself but with external causes
this is how i'm generating my project from scratch if you proceed this way you will probably dont have any more issues and will be able to run spree 3.5 just fine
Spree base installation from scratch
** Assuming you have an empty rails app **
Update Gemfile
gem 'spree', '~> 3.5.0'
gem 'spree_auth_devise', '~> 3.3'
gem 'spree_gateway', '~> 3.3'
Install development dependencies
1) bundle update i18n (i'm thinking this is optional but not sure)
2) bundle install
Install install generators to set up Spree:
1) rails g spree:install --user_class=Spree::User
You will be asked to setup an admin account
Email [spree#example.com]: admin#cucg.com
Password [spree123]:
then just run rails s and you will be all set
I just followed this Spree Official Installation Guide and everything worked jut fine
You need to include html to your haml file name.
Like so:
your_file_name.html.haml
Rename your index file to:
index.html.haml
Read more about haml here:
http://haml.info/tutorial.html
I am using rails version 3.2.12 and was using .erb templates for my view.
Now I want to start using haml templates.
I added haml and haml-rails to the gem file and installed the bundle.
Using haml (4.0.0)
Installing haml-rails (0.4)
I have made a mock-up application.html.haml
!!! 5
%html
%head
%title Rotten Potatoes!
= stylesheet_link_tag 'application'
= javascript_include_tag 'application'
= csrf_meta_tags
%body
= yield
I then changed the application_controller.rb to
class ApplicationController < ActionController::Base
layout "application"
protect_from_forgery
include SessionsHelper
end
when I run this I get the following error message:
Missing template layouts/application with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/home/coen/Desktop/rails_project/sample_app/app/views"
it seems as if the haml handler not installed.
How can I accomplish this?
Well, have you restarted your development server? It is very important thing to do after adding a gem to Gemfile.
BTW. I use haml all the time, i haven't ever used 'haml-rails'.
When i start fresh project, the only thing i do is add "gem 'haml'" to Gemfile and everything works just like it supposed to work.
I have tried to render some files with HAML in Rails 3 without success.
My testfiles have the extension .html.haml.
In my Gemfile, I have the line gem 'haml' and have run bundle install.
When I run my app, I get the following error:
Template is missing
Missing template posts/index with {:locale=>[:en, :en], :formats=>[:html], :handlers=>[:rjs, :rhtml, :rxml, :builder, :erb]} in view paths "/Users/piet/Sites/blog/app/views"`
Any idea on how to resolve this?
For rails 3 all you need to do is add:
gem "haml-rails"
to your Gemfile, then do a "bundle install"
See https://github.com/indirect/haml-rails
If you still seeing the error try restarting your server.
If you are upgrading from Rails 2 to Rails 3, make sure that this is close to the top of your config/application.rb file:
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
It should be right below
# Put this in config/application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
HAML does work without issue in Rails 3.. Two things:
Make sure your route file has resources :posts
Make sure you have the file app/views/posts/index.html.haml
Could you try that? And confirm that Andrew's comment about restarting Rails has been tried as well.