일부 사용자 지정이 필요한 다른 컨트롤러에서 재정의 할 수있는 기능으로 응용 프로그램 컨트롤러에서 인덱스 & 동작을 표시하기 위해 기본 respond_to를 정의하는 방법이 있는지 궁금합니다.응용 프로그램 컨트롤러에서 색인 및 표시 작업에 대한 기본 respond_to를 정의하려면 어떻게합니까?
예를 들어 더 쉽게 생각할 수 있습니다.
내 PDF를 생성하고 사용자를 인증하기 위해 InheritedResources, CanCan/Authlogic 및 WickedPDF 보석을 사용하고 있습니다. 내 코드를 말라 버릴 수 있는지 궁금해서. 여기
내가이 잘 작동
class ProductsController < InheritedResources::Base
load_and_authorize_resource
respond_to :html, :xml, :json, :pdf
def index
@products = Product.page(params[:page])
index! do |format|
format.pdf do
render :pdf => pdf_file_name,
:show_as_html => params[:debug].present?
end
end
end
def show
show! do |format|
format.pdf do
render :pdf => pdf_file_name,
:show_as_html => params[:debug].present?
end
end
end
end
class CustomersController < InheritedResources::Base
def index
index! do |format|
format.pdf do
render :pdf => pdf_file_name,
:show_as_html => params[:debug].present?
end
end
end
def show
show! do |format|
format.pdf do
render :pdf => pdf_file_name,
:show_as_html => params[:debug].present?
end
end
end
end
을 것입니다. 하지만 필자가 pdf를 생성하고자하는 모든 컨트롤러에서 format.pdf를 정의해야 할 필요가 없어 보인다. 이것을 응용 프로그램 컨트롤러로 옮기거나 상속 된 리소스를 사용하여 어딘가에 지정하는 방법이 있습니까? 그리고 컨트롤러별로이 옵션을 무시하십시오. 어떤 아이디어?
내가 다른 관심있는 사람들을위한 다음과 같은 솔루션을 함께했다 당신이