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!
Related
I generated a new model called Comment.
rails g model Comment user_id:integer content:text
rake db:migrate
Then I create a simple partial view, that I intend to call from another controller/view.
Inside of a Product show view:
.comments
h3
| Questions and Answers:
small for #{#product.name}
= render 'comments/new'
Missing partial comments/new with {:locale=>[:en], :formats=>[:html],
:handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :slim, :coffee]}.
Searched in: *
"/Users/sergiotapia/Documents/Work/foobar/app/views"
I stopped and started the Rails application and it's still refusing to detect the partial. Am I overlooking something?
I would prefer not to move the comment form to the Products folder.
Incorrect File Extension
Rename partial file to _new.html.slim. Currently html is misspelt as hmtl.
Try this out:
2.2.4 Rendering an Arbitrary File
The render method can also use a view that's entirely outside of your
application (perhaps you're sharing views between two Rails
applications):
render "/u/apps/warehouse_app/current/app/views/products/show"
Rails determines that this is a file render because of the leading
slash character. To be explicit, you can use the :file option (which
was required on Rails 2.2 and earlier):
render file:"/u/apps/warehouse_app/current/app/views/products/show"
The :file option takes an absolute file-system path. Of course, you
need to have rights to the view that you're using to render the
content.
Taken from here: http://guides.rubyonrails.org/layouts_and_rendering.html
EDIT:
Oh sure, the file name is not correct, didn't see that. ;) See Kirti Thorat's answer.
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.
This really caught me unguarded. The stocks/index.html.haml renders without problem in browser after I installed the haml-rails gem. However, when I tried to test it using rspec/capybara
describe "StockPages" do
describe "stocks/index.html.haml" do
before {visit stocks_path}
subject {page}
it { should have_selector('table#Result') }
end
end
I got this error:
Failure/Error: before {visit stocks_path}
ActionView::MissingTemplate:
Missing template stocks/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}.
How do I solve this?
Thanks
In order to render Haml templates, you need the haml gem loaded. haml-rails does call require 'haml', but if you’ve only added haml-rails to the development group in your Gemfile then haml will also only get loaded in development.
In order to fix this, you need to either move haml-rails out of any group so that it always gets loaded (and so haml also always gets loaded), or add gem 'haml' to your Gemfile (outside of any group). The first option (move haml-rails out of the development group) is likely the easiest, but you might want to leave it in the development group and explicitly add gem 'haml' in order to avoid loading unneeded code in production.
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 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.