I am trying to set up a custom partial for my exception notification mails in a Rails 3 app using the current version (2.4.0) of the exception_notification gem
The README clearly states that "you can customize how each of those
sections are rendered by placing a partial named for that part in your
app/views/exception_notifier directory [...] You can even add new sections that
describe application-specific data"
And I am exactly trying these: Altering existing sections and adding a new custom section. When just altering a section, my changed partial (app/views/exception_notifier/_session.text.erb) has no effect. When I add a new custom section, I get the following error in the log:
ActionView::Template::Error (Missing partial exception_notifier/user with {:formats=>
[:text], :handlers=>[:haml, :rjs, :rhtml, :builder, :erb, :rxml], :locale=>[:de]} in
view paths "/usr/lib/ruby/gems/1.8/gems/exception_notification-2.4.0/lib/exception_notifier/views"):
What am I doing wrong? I suspect that the view path is somehow messed up and that the exception_notifier doesn't bother to look in my /app/views/exception_notifier directory at all.
When exception_notification is used as a gem, the only view_path configured for the notifier is the gem own view path.
In order to override default section template or add you your own you will have to add your application template folder in the view path
Just add to your initializer
ExceptionNotifier::Notifier.prepend_view_path File.join(Rails.root, 'app/views')
If you have your own section partial don't forget to add it in the middleware options
Whatever::Application.config.middleware.use ExceptionNotifier,
:email_prefix => "[Whatever] ",
:sender_address => %{"notifier" <notifier#example.com>},
:exception_recipients => %w{exceptions#example.com},
:sections => %w{my_section1 my_section2} + ExceptionNotifier::Notifier.default_sections
From version 2.6.0 of the gem and forth, this is no longer needed.
That bug is already fixed, so there's no need to have that line on an initializer anymore.
Related
I am trying to use Deface gem for customizing a view that is located in gem (it is not spree).
The path to the view is:
my_gem/backend/layout/sidebar
When I run:
rake deface:test_selector['my_gem/backend/layout/sidebar','.mainnav ul']
I get two matches, the view and proper matching elements are correctly displayed.
However when I run:
rake deface:get_result['my_gem/backend/layout/sidebar']
nothing is changed in the view and apart from its code,"Overrides(0) found" is displayed.
My Override is located in: /app/overrides/add_slider_to_sidebar.rb file:
Deface::Override.new(:virtual_path => 'my_gem/backend/layout/sidebar',
:name => 'add_slider_to_sidebar',
:insert_bottom => ".mainnav ul",
gem:text => "<li>AAAAA</li>")
What should I change (or add to configuration) to allow deface to find my override?
I am using rails 4.0.5, deface 1.0.0 and nokogiri 1.6.2.1.
Edit:
I've made following tests:
Add deface to the application, and do the change mentioned above. Everything worked fine.
Add deface to the gem - so test in dummy application. The behavior described above has occurred.
Add gem with deface view modifications from point 2 but to regular application, not the dummy one. The above behavior has occurred.
I'm a newbie in ruby on rails Web-Programming. Today I tried to set up Ruby programming language and also the Rails framework. Ruby works properly, I made a first Test-Class Successfull. Only setting up my Rails framework prepares me some problem.
I made a test_app and i tried to run it.
rails new test_app
rails s
I realized that the the routes was commented in routes.rb and I uncommented it.
I changed #root :to => 'welcome#index' to root :to => 'welcome#index'.
I also realized that I do not had a controller for the page welcome/index and i created it
with rails g controller Welcome index.
But It do not work yet? Anybody an idea?
Template is missing
Missing template welcome/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "D:/Davide Giunta/Development/workspace[ruby]/test_app/app/views"
Ruby Version: 1.9.3p368
Gem Version: 1.8.24
Rails Version: 3.2.11
rails g controller will only create the controller part, you also need to create a corresponding view file, in this case, you want app/views/welcome/index.html.erb
Using scaffold (only while learning), or resource for your generator might be faster. (I usually create them all by hand these days)
The answer from Jim Deville is correct. You need to create corresponding view file of your controller's action (action_name.html.erb) and place it to views dir under subdirectory named like your controller.
See basics of Rails here http://guides.rubyonrails.org/getting_started.html.
When you want to create action with controller, view and model you should use rails g scaffold SomeName also see http://guides.rubyonrails.org/getting_started.html#getting-up-and-running-quickly-with-scaffolding.
When I generate a new controller, under a subfolder, it now cannot find the templates, even though other controllers in the same 'structure' are working:
I have the following controller which sits in app/members/group_controller.rb (created by a rails g controller Members::Group command)
class Members::GroupController < ApplicationController
def index
render :layout => 'dashboard'
end
end
I have a template in views/members/group/index.html.erb
I have the following relevant line in routes.rb (ie leaving out some others for clarity):
namespace :members do
match '/group' => 'group#index'
end
rake routes shows me the following relevant line:
members_group /members/group(.:format) members/group#index
When I type the url http://127.0.0.1:3000/members/group, I get the Template Missing error as follows:
Template is missing
Missing template members/group/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :arb, :coffee]}. Searched in: * "/Users/mitch/Documents/Development/TME/app/views" * "/Users/mitch/.rvm/gems/ruby-1.9.2-p290/bundler/gems/active_admin-7c3e25f30224/app/views" * "/Users/mitch/.rvm/gems/ruby-1.9.2-p290/gems/kaminari-0.13.0/app/views" * "/Users/mitch/.rvm/gems/ruby-1.9.2-p290/gems/devise-2.0.0/app/views"
The routing is working to the index method, because I can eg put in a redirect and it gets acted upon, but I cannot get the template to display.
Why so?
Thanks
(Rails 3.1)
This seems to be linked to how I generate the controller in the first place.
I used upper case as follows:
rails g controller Members::Group (and tried a few other test controllers similarly, destroying them and recreating them)
When I destroyed the controller and ran the lower case equivelant:
rails g controller members::group all works fine and the templates can be found
I can't find any info elsewhere to support this though...
I observe that you render dashboard layout in groups index page please check path of dashboard .Is it in right place????
I had the exact same problem. When I used terminal to navigate to the directory and listed the files in /layouts, I had one layout file appear as a red, archived file. I have no idea why.
To fix it: simply copy&paste the code from the layout file, delete the layout file (rm "file"), and then create the same layout using the terminal via:
touch file_name.html.erb
Paste your code into the new file and it should work.
I dropped the gem into the gem file, bundle installed it.
Have this in my application.rb:
require 'pdfkit'
config.middleware.use PDFKit::Middleware, :print_media_type => true
Doing rake middleware, I see 'use PDFKit::Middleware' in there.
I have this in my routes
match "/option_invoice/view_invoice/(/:id)" => "option_invoice#view_invoice"
Now when I go to http://0.0.0.0:3000/option_invoice/view_invoice/2.pdf, I got the missing template error. The page without the .pdf displays perfectly fine.
Missing template option_invoice/view_invoice, application/view_invoice with {:formats=>> >[:pdf], :locale=>[:en], :handlers=>[:coffee, :erb, :builder, :arb]}.
I'm on rails 3.2.2 if that helps.
Any help?
Basically you're just missing a template in given paths that corresponds to view_invoice.pdf.erb or view_invoice.pdf.haml or whatever you are using.
Either you create that and render whichever view you want in the PDF or you override the default template pulled by PDFKit.
I would recommend the first variant, this makes the rendered PDF independent of your views (kind of).
Cheers!
I'm trying to create two static pages and I have the following error:
Missing template static_pages/index with {:formats=>[:html], :locale=>[:en, :en], :handlers=>[:rhtml, :rxml, :builder, :erb, :rjs]} in view paths "F:/assignment/app/views"
I am new to rails and web development in general, so it's probably something simple.
I have followed this link to get to the stage I am now at: Static pages in Ruby on Rails
I am trying to create two static pages, one called About and one called Help in a basic blog application. When I have created the controller I have called it 'static_pages' as I already have a pages controller.
Can anybody offer any advice on where I'm going wrong?
I hope I understand you correctly if I say you want a path like localhost:3000/About
In that case, you want to create a method with the same name as the view (About.html) in your static_pages controller.
def About
end
(Notice case sensitivity)
The About.html file should be placed within the /static_pages directory. And in the routes.rb file, you should have:
match '/About' => 'static_pages#About'
Hope this helps.