0

私は持っている...

/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

複数のコントローラで定義された印刷アクションからこの印刷レイアウト ファイルにアクセスしたいと考えています。

admin としてログインして にアクセスするとhttp://localhost:3000/documents/1/print、このエラーが発生するのはなぜですか?

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"

print.html.hamlファイルを移動する/app/views/application//app/views/documents/、エラーを変更しますが、それを取り除くことはできません。

4

1 に答える 1

0

これは、レイアウトを定義したが、おそらく印刷アクション用のテンプレート ファイルがないためです。レイアウト ファイルは、存在しない (印刷アクション) テンプレートからコンテンツを作成しようとしています。レンダリングする (アクション) テンプレートをさらに指定するか、単に追加する必要がありますapp/views/documents/print.html.haml。また、混乱を避けるために、レイアウト ファイルの名前を変更します。

于 2013-01-31T10:04:04.630 に答える