Question

I have...

/config/routes.rb:

resources :documents do
   member do
      get :print
   end
end

/config/authorization_rules.rb:

role :admin do
    has_permission_on [:documents], :to => [:print]
  end

app/controllers/documents_controller.rb:

def print
  render :layout => "print"
end

app/views/layouts/print.html.haml:

!!!
%html
  %body
    = yield

I want to access this print layout file from print actions defined in several controllers.

Why, when I am logged in as admin and go to http://localhost:3000/documents/1/print, do I get this error?

Missing template documents/print, application/print with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :haml]}. Searched in:
  * "/Users/steven/Dropbox/testivate/app/views"
  * "/Users/steven/.rvm/gems/ruby-1.9.2-p320/gems/declarative_authorization-0.5.6/app/views"

Moving the print.html.haml file to /app/views/application/ or /app/views/documents/ changes the error but does not get rid of it.

Was it helpful?

Solution

This is because you have defined layout but probably don't have template file for your print action. Your layout file tries to yield contents from (print action) template which doesn't exist. You need to additionally specify which (action) template you want to render, or just add app/views/documents/print.html.haml. Also, to avoid confusion, rename your layout file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top