Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's causing this error? ActionView::Template::Error: ActionController::Metal#session delegated to @_request.session, but @_request is nil
    primarykey
    data
    text
    <p>In <code>/app/models/review.rb</code>, I have the a method that's designed to create a PDF from the output of the <code>review#print</code> action. Also designed to capture my entire print stylesheet and inline it in the header when I'm in production mode:</p> <pre><code>def create_pdf snip # code that sets @competitors, @elements &amp; @questions css = Rails.application.assets.find_asset('print').to_s if Rails.env.production? html = ActionController::Base.new.render_to_string "reviews/print", :locals =&gt; {:@review =&gt; self, :@competitors =&gt; @competitors, :@elements =&gt; @elements, :@questions =&gt; @questions, :@css =&gt; css} pdf = HyPDF.new(html, :test =&gt; 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) # for debugging -- so I can see &lt;head&gt; end </code></pre> <p>I have tried many variants of this code, including passing <code>:layouts =&gt; false</code> and more to <code>render</code>.</p> <p>My <code>reviews_controller.rb</code> contains:</p> <pre><code>class ReviewsController &lt; ApplicationController respond_to :html filter_access_to :all layout "print", :only =&gt; [:print, :pdf] def print snip # code that sets @review, @competitors, @elements @questions respond_with(@review) end end </code></pre> <p>My <code>app/views/reviews/print.html.haml</code> contains:</p> <pre><code>!!! %html %head %title Testivate - if @css.present? = content_tag(:style, @css.html_safe, :type =&gt; "text/css") - else = stylesheet_link_tag "print", :media =&gt; "print, screen, projection" </code></pre> <p>Why, then, do I get the following error when I call <code>@review.create_pdf</code>?</p> <pre><code>Rendered reviews/print.html.haml (366.3ms) ActionView::Template::Error: ActionController::Metal#session delegated to @_request.session, but @_request is nil: #&lt;ActionController::Base:0x00000002bffd40 @_routes=nil, @_action_has_layout=true, @_headers={"Content-Type"=&gt;"text/html"}, @_status=200, @_request=nil, @_response=nil, @_prefixes=["action_controller/base"], @_lookup_context=#&lt;ActionView::LookupContext:0x00000002bec560 @details_key=#&lt;ActionView::LookupContext::DetailsKey:0x000000096296a8 @hash=-2527668597365468702&gt;, @details={:locale=&gt;[:en], :formats=&gt;[:html], :handlers=&gt;[:erb, :builder, :haml]}, @skip_default_locale=false, @cache=true, @prefixes=["action_controller/base"], @rendered_format=:html, @view_paths=#&lt;ActionView::PathSet:0x00000002bec4c0 @paths=[/app/app/views, /app/vendor/bundle/ruby/1.9.1/gems/declarative_authorization-0.5.7/app/views]&gt;&gt;, @_view_renderer=#&lt;ActionView::Renderer:0x00000002be4a18 @lookup_context=#&lt;ActionView::LookupContext:0x00000002bec560 @details_key=#&lt;ActionView::LookupContext::DetailsKey:0x000000096296a8 @hash=-2527668597365468702&gt;, @details={:locale=&gt;[:en], :formats=&gt;[:html], :handlers=&gt;[:erb, :builder, :haml]}, @skip_default_locale=false, @cache=true, @prefixes=["action_controller/base"], @rendered_format=:html, @view_paths=#&lt;ActionView::PathSet:0x00000002bec4c0 @paths=[/app/app/views, /app/vendor/bundle/ruby/1.9.1/gems/declarative_authorization-0.5.7/app/views]&gt;&gt;, @_template_renderer=#&lt;ActionView::TemplateRenderer:0x00000009637870 @lookup_context=#&lt;ActionView::LookupContext:0x00000002bec560 @details_key=#&lt;ActionView::LookupContext::DetailsKey:0x000000096296a8 @hash=-2527668597365468702&gt;, @details={:locale=&gt;[:en], :formats=&gt;[:html], :handlers=&gt;[:erb, :builder, :haml]}, @skip_default_locale=false, @cache=true, @prefixes=["action_controller/base"], @rendered_format=:html, @view_paths=#&lt;ActionView::PathSet:0x00000002bec4c0 @paths=[/app/app/views, /app/vendor/bundle/ruby/1.9.1/gems/declarative_authorization-0.5.7/app/views]&gt;&gt;, @view=#&lt;#&lt;Class:0x00000002be4950&gt;:0x000000096da390 @_config={}, @view_renderer=#&lt;ActionView::Renderer:0x00000002be4a18 ...&gt;, @_routes=nil, @_assigns={"_routes"=&gt;nil}, @_controller=#&lt;ActionController::Base:0x00000002bffd40 ...&gt;, @_request=nil, @view_flow=#&lt;ActionView::OutputFlow:0x000000096da200 @content={}&gt;, @output_buffer="", @virtual_path="reviews/print", @competitors=[#&lt;Competitor id: 56, etc etc...&gt;, @css="html,body,div,span,applet,object,iframe,etc ... (which is the css reset at the start of my stylseheet) ...on:none}\n", etc </code></pre> <p><strong>Update:</strong></p> <p>I tried creating the method from a Controller action on Review, rather than a class method, but I got the same <code>ActionView::Template::Error:</code> error.</p> <p><strong>Update 2:</strong></p> <p>The view code as requested to check it's not trying to access session:</p> <p>(I don't think it is.)</p> <pre><code>!!! %html %head %title Testivate - if @css.present? = content_tag(:style, @css.html_safe, :type =&gt; "text/css") - else = stylesheet_link_tag "print", :media =&gt; "print, screen, projection" = csrf_meta_tag = analytics_init if Rails.env.production? %body .header .imagebox =image_tag "Testivate-logo.svg", :width =&gt; "300" %h1#first Confidential Competitive Website Review &amp; Benchmark .imagebox =image_tag @review.owner_logo.url .body %p Review conducted for #{@review.client_name}. .header %h1 Research overview .body %p The methodology that drives this research is #{@review.product.full_name}. = raw @review.product.description %p Between #{@review.created_at.full_date} and #{@review.updated_at.full_date}, Testivate tested and compared #{pluralize @review.competitors.count, "website"}: - @competitors.sort{|c| c.name &lt;=&gt; c.name}.each do |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 the review group with a 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 do |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 The research involve testing #{pluralize @elements.count, "element"}: %table %thead %tr %th Element: - @elements.each do |element| %th= element.name %tbody - @competitors.each do |competitor| %tr %td.first= competitor.name - @elements.each do |element| %td.not_controls= competitor.element_score(element) .header %h1 Website testing standards .body %p The research involve testing #{pluralize Standard.all.count, "standard"}: %table %thead %tr %th Standard: - Standard.all.each do |standard| %th= standard.name %tbody - @competitors.each do |competitor| %tr %td.first= competitor.name - Standard.all.each do |standard| %td.not_controls= competitor.standard_score(standard) - @questions.each do |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 do |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 To understand more about how this question was scored or how to fix any problems that were uncovered, consult the following references: = raw question.endmatter </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload