次のようなコントローラーでメソッドを定義しました。
def self.dailymail
.... #fill data from db
ac = ActionController::Base.new()
kit = PDFKit.new(ac.render_to_string(:action => "formatinhtml.html.erb",:rawdata => data))
pdf = kit.to_pdf
... #send pdf in mail
end
formathtml は次のようになります。
def formatinhtml
@dailyrep = params[:rawdata]
respond_to do |format|
format.html # daily.html.erb
end
end
モデルから呼び出し、rufus スケジューラーから呼び出すことができるように、self.dailymail を使用する必要があります。
しかし、それでも次のようなエラーが発生します。
scheduler caught exception:
Missing template action_controller/base/daily.html with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip, :xls], :handlers=>[:erb, :builder, :coffee]}. Searched in:
* "F:/DEVELOPMENT/TrackIt/app/views"
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_view/path_set.rb:58:in `find'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_view/lookup_context.rb:109:in `find'...
それで、私は何をする必要がありますか?
更新:デバッグ後、アクションformatinhtml
が実際には呼び出されていないことがわかりました。必要なルートを定義しました。