未初始化的常量(名称错误)

时间:2016-07-05 11:46:52

标签: ruby-on-rails

actor_drawer.rb

def self.draw(actor)
  pdf = PDF::Writer.new
  actors.each do |actor|
    pdf.text actor.name
  end
      pdf.render
end

screenshot of actor_drawer.rb

 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' "

1 个答案:

答案 0 :(得分:0)

您的actor_drawer.rb不包含ActorDrawer课程/模块

class ActorDrawer
  def self.draw(actors)
     # all other code
  end
end