yappbox/render_anywhere

can't use fragment caching with render_anywhere

Closed this issue · 15 comments

Hi there,

When I try to use fragment caching with render_anywhere, I get this error:

Rendered reviews/print.html.haml within layouts/print (592.2ms)
ActionView::Template::Error: undefined method `perform_caching' for #<RenderAnywhere::RenderingController:0x007fb5e9c7dcc8>
from /Users/steven/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.11/lib/action_view/helpers/cache_helper.rb:35:in `cache'

In production.rb and development.rb I have:

config.action_controller.perform_caching = true

Hi Steven,

I'm away this weekend but I'll take a look next week. Can you let me know what version of Rails you're using and if possible provide a snippet of code of how you're using this to get this error?

Thanks

On 29 Nov 2013, at 00:55, Steven Noble notifications@github.com wrote:

Hi there,

When I try to use fragment caching with render_anywhere, I get this error:

Rendered reviews/print.html.haml within layouts/print (592.2ms)
ActionView::Template::Error: undefined method perform_caching' for #<RenderAnywhere::RenderingController:0x007fb5e9c7dcc8> from /Users/steven/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.11/lib/action_view/helpers/cache_helper.rb:35:incache'
In production.rb and development.rb I have:

config.action_controller.perform_caching = true

Reply to this email directly or view it on GitHub.

Thanks. I'm on Rails 3.2.1. I call it like this:

require 'render_anywhere'
class Review < ActiveRecord::Base
  include RenderAnywhere

  def create_pdf
    css = Rails.application.assets.find_asset('print').to_s
    @mc = marker_count
    html = render "/reviews/print", :layout => "print", :locals => {:@review => self, 
                                                                    :@competitors => sorted_competitors, 
                                                                    :@elements => elements, 
                                                                    :@standards => standards, 
                                                                    :@batteries => batteries, 
                                                                    :@css => css, 
                                                                    :@base => base,
                                                                    :@element_scores_chart => element_scores_chart(@mc),
                                                                    :@standard_scores_chart => standard_scores_chart(@mc)}
    @response = DocRaptor.create(:document_content => html, :document_type => "pdf", :test => !Rails.env.production?, :no_subset_fonts => true).body
    s3 = AWS::S3.new :access_key_id => ENV["S3_ACCESS_KEY_ID"], :secret_access_key => ENV["S3_SECRET_ACCESS_KEY"]
    bucket_name = "Testivate" if Rails.env.production?
    bucket_name = "Testivate-staging" if Rails.env.staging?
    bucket_name = "Testivate-localhost" if Rails.env.test? || Rails.env.development?
    bucket = s3.buckets[bucket_name]
    @uploadname = [client_name, "/", product.short_name, "_", Time.now.in_time_zone("Sydney").full_time, "_", SecureRandom.uuid, ".pdf"].join.downcase.gsub(/\W*&\W*|\s+/, "_").gsub("-", "")
    obj = bucket.objects[@uploadname]
    upload = obj.write(@response)    
    obj.acl = :public_read
    client = Googl.client("orders@testivate.com", ENV["GMAIL_PASSWORD"])
    update_attribute :latest_url, client.shorten("http://s3.amazonaws.com/#{bucket_name}/#{@uploadname}").short_url
    NotificationMailer.pdf_creation(self).deliver
  end  

And the actual caching occurs in a template?
On 29 Nov 2013 16:12, "Steven Noble" notifications@github.com wrote:

Thanks. I'm on Rails 3.2.1. I call it like this:

require 'render_anywhere'
class Review < ActiveRecord::Base
include RenderAnywhere

def create_pdf
css = Rails.application.assets.find_asset('print').to_s
@mc = marker_count
html = render "/reviews/print", :layout => "print", :locals => {:@review => self,
:@Competitors => sorted_competitors,
:@elements => elements,
:@standards => standards,
:@Batteries => batteries,
:@css => css,
:@base => base,
:@element_scores_chart => element_scores_chart(@mc),
:@standard_scores_chart => standard_scores_chart(@mc)}
@response = DocRaptor.create(:document_content => html, :document_type => "pdf", :test => !Rails.env.production?, :no_subset_fonts => true).body
s3 = AWS::S3.new :access_key_id => ENV["S3_ACCESS_KEY_ID"], :secret_access_key => ENV["S3_SECRET_ACCESS_KEY"]
bucket_name = "Testivate" if Rails.env.production?
bucket_name = "Testivate-staging" if Rails.env.staging?
bucket_name = "Testivate-localhost" if Rails.env.test? || Rails.env.development?
bucket = s3.buckets[bucket_name]
@uploadname = [client_name, "/", product.short_name, "", Time.now.in_time_zone("Sydney").full_time, "", SecureRandom.uuid, ".pdf"].join.downcase.gsub(/\W_&\W_|\s+/, "_").gsub("-", "")
obj = bucket.objects[@uploadname]
upload = obj.write(@response)
obj.acl = :public_read
client = Googl.client("orders@testivate.com", ENV["GMAIL_PASSWORD"])
update_attribute :latest_url, client.shorten("http://s3.amazonaws.com/#{bucket_name}/#{@uploadname}").short_url
NotificationMailer.pdf_creation(self).deliver
end


Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-29537852
.

Yes. Sorry. A snippet:

    - @batteries.each do |battery|
      - cache battery do
        .section{:id => "#{@chapter}"}
          - @chapter += 1
          %h2 Question: &ldquo;#{battery.description}&rdquo;
          %p The website element this question checked: #{battery.element_name}
          %p The quality standard this question checked: #{battery.standard_name}

There's caching elsewhere in the template too. It's necessary as the template builds a 100+ page PDF from 1000s of data points and reams of conditional logic.

Great, thanks. I'll take a look soon.
On 29 Nov 2013 16:46, "Steven Noble" notifications@github.com wrote:

Yes. Sorry. A snippet:

- @batteries.each do |battery|
  - cache battery do
    .section{:id => "#{@chapter}"}
      - @chapter += 1
      %h2 Question: &ldquo;#{battery.description}&rdquo;
      %p The website element this question checked: #{battery.element_name}
      %p The quality standard this question checked: #{battery.standard_name}

There's caching elsewhere in the template too. It's necessary as the
template builds a 100+ page PDF from 1000s of data points and reams of
conditional logic.


Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-29538780
.

Hey robb1e -- any progress on this? Cheers

Sorry @snoblenet I haven't had a chance. I will try to take a look this week.

Hi @snoblenet, sorry it's been so long getting back to you. I think I've made a change to fix this. If you update to v0.0.5 hopefully it'll work. I created a small Rails app using 3.2.16 and got the same issue as you, then resolved it with the change. Can you give it a try and let me know how you get on.

Thanks

Thanks. I've temporarily broken the features that uses render_anywhere on the main branch but as soon as it's working again I'll do this and let you know what happens. Cheers.

That fixed it for me. Thanks for the update.

@snoblenet Are you using cache digests? I only ask, because I'm having the same problem, but with a different error thrown from c_d:

 undefined local variable or method `view_cache_dependencies'

I guess I am using them implicitly in that I'm doing things like:

- cache [@report, element] do

So then not actually using the cache_digests gem? I might have to fork this and add some includes to get it working.

Using Rails 4 which I thought bundled the cache_digests functionality that was previously provided through a gem.

Right your are, still on 3.2.17 on this app here. Thanks for the responses!

Jarrett Green
CHIEF PRODUCT DEVELOPMENT OFFICER


tel. 316-927-2668
www. balancedcomp.com
tw. @balancedcomp

BalancedComp

Calibrating Pay-to-Performance for Financial Institutions

On Fri, Mar 7, 2014 at 3:08 PM, Steven Noble notifications@github.comwrote:

Using Rails 4 which I thought bundled the cache_digests functionality that
was previously provided through a gem.

Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-37067801
.