ruby on rails - What's causing this error? ActionView::Template::Error: ActionController::Metal#session delegated to @_request.session, but @_request is nil -
in /app/models/review.rb
, have method that's designed create pdf output of review#print
action. designed capture entire print stylesheet , inline in header when i'm in production mode:
def create_pdf snip # code sets @competitors, @elements & @questions css = rails.application.assets.find_asset('print').to_s if rails.env.production? html = actioncontroller::base.new.render_to_string "reviews/print", :locals => {:@review => self, :@competitors => @competitors, :@elements => @elements, :@questions => @questions, :@css => css} pdf = hypdf.new(html, :test => true) upload = pdf.upload_to_s3("testivate", [self.id, "_", time.now.full_time, ".pdf"].join.downcase.gsub(" ", "_"), true) self.update_attribute :latest_url, upload notificationmailer.pdf_creation(self).deliver return html.to_s.truncate(300) # debugging -- can see <head> end
i have tried many variants of code, including passing :layouts => false
, more render
.
my reviews_controller.rb
contains:
class reviewscontroller < applicationcontroller respond_to :html filter_access_to :all layout "print", :only => [:print, :pdf] def print snip # code sets @review, @competitors, @elements @questions respond_with(@review) end end
my app/views/reviews/print.html.haml
contains:
!!! %html %head %title testivate - if @css.present? = content_tag(:style, @css.html_safe, :type => "text/css") - else = stylesheet_link_tag "print", :media => "print, screen, projection"
why, then, following error when call @review.create_pdf
?
rendered reviews/print.html.haml (366.3ms) actionview::template::error: actioncontroller::metal#session delegated @_request.session, @_request nil: #<actioncontroller::base:0x00000002bffd40 @_routes=nil, @_action_has_layout=true, @_headers={"content-type"=>"text/html"}, @_status=200, @_request=nil, @_response=nil, @_prefixes=["action_controller/base"], @_lookup_context=#<actionview::lookupcontext:0x00000002bec560 @details_key=#<actionview::lookupcontext::detailskey:0x000000096296a8 @hash=-2527668597365468702>, @details={:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :haml]}, @skip_default_locale=false, @cache=true, @prefixes=["action_controller/base"], @rendered_format=:html, @view_paths=#<actionview::pathset:0x00000002bec4c0 @paths=[/app/app/views, /app/vendor/bundle/ruby/1.9.1/gems/declarative_authorization-0.5.7/app/views]>>, @_view_renderer=#<actionview::renderer:0x00000002be4a18 @lookup_context=#<actionview::lookupcontext:0x00000002bec560 @details_key=#<actionview::lookupcontext::detailskey:0x000000096296a8 @hash=-2527668597365468702>, @details={:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :haml]}, @skip_default_locale=false, @cache=true, @prefixes=["action_controller/base"], @rendered_format=:html, @view_paths=#<actionview::pathset:0x00000002bec4c0 @paths=[/app/app/views, /app/vendor/bundle/ruby/1.9.1/gems/declarative_authorization-0.5.7/app/views]>>, @_template_renderer=#<actionview::templaterenderer:0x00000009637870 @lookup_context=#<actionview::lookupcontext:0x00000002bec560 @details_key=#<actionview::lookupcontext::detailskey:0x000000096296a8 @hash=-2527668597365468702>, @details={:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :haml]}, @skip_default_locale=false, @cache=true, @prefixes=["action_controller/base"], @rendered_format=:html, @view_paths=#<actionview::pathset:0x00000002bec4c0 @paths=[/app/app/views, /app/vendor/bundle/ruby/1.9.1/gems/declarative_authorization-0.5.7/app/views]>>, @view=#<#<class:0x00000002be4950>:0x000000096da390 @_config={}, @view_renderer=#<actionview::renderer:0x00000002be4a18 ...>, @_routes=nil, @_assigns={"_routes"=>nil}, @_controller=#<actioncontroller::base:0x00000002bffd40 ...>, @_request=nil, @view_flow=#<actionview::outputflow:0x000000096da200 @content={}>, @output_buffer="", @virtual_path="reviews/print", @competitors=[#<competitor id: 56, etc etc...>, @css="html,body,div,span,applet,object,iframe,etc ... (which css reset @ start of stylseheet) ...on:none}\n", etc
update:
i tried creating method controller action on review, rather class method, got same actionview::template::error:
error.
update 2:
the view code requested check it's not trying access session:
(i don't think is.)
!!! %html %head %title testivate - if @css.present? = content_tag(:style, @css.html_safe, :type => "text/css") - else = stylesheet_link_tag "print", :media => "print, screen, projection" = csrf_meta_tag = analytics_init if rails.env.production? %body .header .imagebox =image_tag "testivate-logo.svg", :width => "300" %h1#first confidential competitive website review & benchmark .imagebox =image_tag @review.owner_logo.url .body %p review conducted #{@review.client_name}. .header %h1 research overview .body %p methodology drives research #{@review.product.full_name}. = raw @review.product.description %p between #{@review.created_at.full_date} , #{@review.updated_at.full_date}, testivate tested , compared #{pluralize @review.competitors.count, "website"}: - @competitors.sort{|c| c.name <=> c.name}.each |competitor| .imagebox = image_tag competitor.logo.url(:thumb) %h4 #{competitor.name} %h4 #{competitor.url} .header %h1 results summary .body %p #{pluralize @review.winners.count, "entrant"} led review group score of #{@review.top_score}: #{@review.winners.map{|w| w.name}.join("; ")}. %table %thead %tr %th.not_controls website %th score %th.not_controls website %th score %tbody - @competitors.each_slice(2).each |competitor_pair| %tr %td.not_controls= competitor_pair.first.name %td.not_controls= competitor_pair.first.current_score %td.not_controls - unless competitor_pair.count == 1 = competitor_pair.last.name %td.not_controls - unless competitor_pair.count == 1 = competitor_pair.last.current_score .header %h1 tested website elements .body %p research involve testing #{pluralize @elements.count, "element"}: %table %thead %tr %th element: - @elements.each |element| %th= element.name %tbody - @competitors.each |competitor| %tr %td.first= competitor.name - @elements.each |element| %td.not_controls= competitor.element_score(element) .header %h1 website testing standards .body %p research involve testing #{pluralize standard.all.count, "standard"}: %table %thead %tr %th standard: - standard.all.each |standard| %th= standard.name %tbody - @competitors.each |competitor| %tr %td.first= competitor.name - standard.all.each |standard| %td.not_controls= competitor.standard_score(standard) - @questions.each |question| .header %h1 question details .body %h3= question.name %p standard: #{question.standard.try(:name)} %p element: #{question.element.try(:name)} %table %thead %tr %th competitor %th score %th explanation %tbody - @competitors.each |competitor| %tr %td.first= competitor.name %td.not_controls= competitor.current_score_for_question(question) %td.not_controls= competitor.explanation_for_score_for_question(question) - unless question.endmatter.blank? %h3 references %p understand more how question scored or how fix problems uncovered, consult following references: = raw question.endmatter
as feckmore said, problem used come csrf_meta_tag inclusion @ layout.
Comments
Post a Comment