actor_drawer.rb
def self.draw(actor)
pdf = PDF::Writer.new
actors.each do |actor|
pdf.text actor.name
end
pdf.render
end
class ActorsController < ApplicationController
require 'actor_drawer'
def new
@actor=Actor.new
end
def index
@actors=Actor.all
@actors = @actors.search(params[:search1] )if (params[:search1] ).present?
respond_to do |format|
format.html
format.pdf do
send_data ActorDrawer.draw(@actors), :filename => 'actors.pdf', :type => 'application/pdf', :disposition => 'inline'
end
end
end
查看:
<p><%= button_to 'PDF Format', actors_path(:pdf) %></p>
错误:
NameError in ActorsController#index uninitialized constant ActorsController::ActorDrawer......error coming at this code " send_data ActorDrawer.draw(@actors), :filename => 'actors.pdf', :type => 'application/pdf', :disposition => 'inline' "
答案 0 :(得分:0)
您的actor_drawer.rb
不包含ActorDrawer
课程/模块
class ActorDrawer
def self.draw(actors)
# all other code
end
end