Rails wiked_pdf page breaks not working - ruby-on-rails

I have a Rails 3.2 app using Bootstrap and Wicked_pdf. I'm trying to page break the pdf after each #costproject.
Gems:
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
I read this post: Rails WickedPDF Page Breaks
So, I tried it.
This is in my CSS:
.page-break {
display:block;
clear:both;
page-break-after:always;
}
And this is in projects.pdf.erb:
<% #costprojects.each do |costproject| %>
<div class="page-break"></div>
<div id="pdfbody">
<table class="table table-striped">
...
But, the page breaks don't happen.
Thanks for the help!

I tried a lot of different approaches.
Placing this code in the viewprojects.pdf.erb worked for me:
<p style='page-break-after:always;'></p>

Related

Wicked_pdf not display image on production but display in local development

I am having very difficulties to display images on production. The images are showing perfectly fine in local development but once it goes to production, it displays nothing. There are a few lines of code I have tried
System.pdf.erb
#1
<img src="'<%= url_for(system.last.image)%>"> <br><br><hr>
#2
<%= wicked_pdf_image_tag
system.last.image.service_url.gsub("https", "http") %>
#3
<%= wicked_pdf_image_tag
system.last.image.service_url.gsub("https", "http") %>
#4
<img src="<%= system.last.image.variant(resize:
"590").processed.service_url %>">
Gemfile
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
None of above works. Please help.

google_visualr chart rendering error

i am trying Google-Visualr gem and got the above error.
As described here.
i installed the gem and in MyModel (we can use controller/model) i copied the demo code for line-chart from here.
i have a UserMailer,where i wanted to render html page along with my chart and using pdfkit i am converting rendered html to pdf.
class UserMailer < ActionMailer::Base
def my_report
#chart =MyModel.line_chart
html_data = render :template => "user_mailer/my_report"
kit = PDFKit.new(html_data,:page_size => 'Letter')
pdf = kit.to_pdf
end
in my my_report view i included
<script src='https://www.google.com/jsapi'></script>
in <head>
included this in <body> part
<div id='chart'></div>
<%= render_chart(#chart, 'chart') %>
But it is leading to me to undefined method "render_chart" error.
Any suggestion that how can i render chart with my html data?
where i am going wrong?
i am using rails 4
and 'google_visualr', '>= 2.1'

Using Spree and Spree Fancy how can I customize the color scheme?

I am new to programming and this is my first Spree app. I am unable to change the color scheme of my app using Spree and Spree Fancy. I've tried following a few tutorials and docs that I've listed below but I am having difficulty implementing Deface and override. I was able to update a page using Deface app/overrides/update_footer.rb file with the following:
Deface::Override.new(:virtual_path => 'spree/shared/_footer',
:name => 'change address to boston',
:replace => "div.address",
:text => "
<div class='address'>
New Location USA
</div>
")
And my Gem file is
gem 'rails', '4.0.3'
gem 'spree', github: 'spree/spree', branch: '2-2-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-2-stable'
gem 'spree_fancy', github: 'spree/spree_fancy'
Links I've tried
http://railscasts.com/episodes/298-getting-started-with-spree?view=asciicast
http://guides.spreecommerce.com/developer/deface_overrides_tutorial.html as well as the guides on assets and views.
What is the correct way to customize the colors? I hope to be able to make other changes of course once I understand the process.
Your deface override is not working because you're trying to replace content which doesn't exist in the template you're overriding.
Take a look at the source for the template here:
https://github.com/spree/spree/blob/v2.2.0/frontend/app/views/spree/shared/_footer.html.erb
I'll paste it below, as it's small.
<footer id="footer" class="sixteen columns" data-hook>
<div id="footer-left" class="columns alpha eight" data-hook>
<p><%= Spree.t :powered_by %> <%= link_to 'Spree', 'http://spreecommerce.com/' %></p>
</div>
<div id="footer-right" class="columns omega eight" data-hook></div>
</footer>
In your deface override, you should see it apply if you change it to override something that is in that template. For example,
:replace => "#footer-left"
If you're just looking to change some of the colours around you should override this file:
https://github.com/spree/spree_fancy/blob/master/app/assets/stylesheets/spree/fancy/variables_override.css.scss
You can then redefine some of the variables listed here:
https://github.com/spree/spree_fancy/blob/a78d4b9017985405b497af9d8d4bc26949d19283/app/assets/stylesheets/spree/fancy/variables.css.scss#L4-L17
You can also style elements by applying new CSS to them, or override the existing styles with higher priority CSS selectors.

rails 4 with CKeditor

I cannot get the galetahub ckeditor gem to work with Rails 4 for me. I searched for any problems online but cannot find any. I'm following the instructions exactly.
I include gem "ckeditor" in my Gemfile
I include gem "carrierwave" and gem "mini_magick"
I run rails generate ckeditor:install --orm=active_record --backend=carrierwave
I run rake db:migrate
Inside application.rb I include config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
Inside routes.rb I have mount Ckeditor::Engine => '/ckeditor'
I'm using SimpleForm so I paste the following ERB <%= f.input :description, as: :ckeditor %> in my view.
And I think that's it. But my text area does not convert to a CKeditor area for some reason.
STEP 1: Add gem 'paperclip' and gem "ckeditor" in your gemfile.
STEP 2: Bundle Install.
STEP 3: rails generate ckeditor:install --orm=active_record --backend=paperclip
STEP 4: Place config.autoload_paths += %W(#{config.root}/app/models/ckeditor) in application.rb
STEP 5: Place mount Ckeditor::Engine => "/ckeditor" if not present in routes.rb already and run db:migrate
STEP 6: Open application.html.erb and place this <%= javascript_include_tag 'ckeditor/ckeditor.js' %> in header.
STEP 7: Place this in footer(above the body tag) in application.html.erb
<script type="text/javascript">$(document).ready(function() {
if ($('textarea').length > 0) {
var data = $('textarea');
$.each(data, function(i) {
CKEDITOR.replace(data[i].id);
});
}
});</script>
STEP 8: Restart the WEBrick SERVER.
That's it.
Else
Download the CKEditor Zip file, extract the files and place them in the sub directory “javascripts/ckeditor”, add the main JS file to the layout..
javascript_include_tag 'ckeditor/ckeditor.js'
Place this in footer(above the body tag) in application.html.erb
<script type="text/javascript">$(document).ready(function() {
if ($('textarea').length > 0) {
var data = $('textarea');
$.each(data, function(i) {
CKEDITOR.replace(data[i].id);
});
}
});</script>
I have the same problem using rails 4 and apparently the problem is that the form helper
form.cktext_area
Or in your case
f.input :description, as: :ckeditor
it's not generating what it supposed to generate, and you don't have to load the editor manually, the only thing you need to do is to is to add the class 'ckeditor' to your textarea and it will load automatically, like this:
f.cktext_area :body, :class => 'ckeditor'
Meanwhile the Galetahub gem has been updated, but it has to be updated in your app manually. Read the github page: https://github.com/galetahub/ckeditor.
ajkumar basically answered the question well already, but if you are still lost, all you need to do is download the js file, include it in your html, have a script snippet included in the HTML to activate ckeditor on a certain textarea tag ID, and then change the class of the "textarea" tag you want to change to ckeditor. Quick sample below
<!DOCTYPE html>
<html>
<head>
<title>A Simple Page with CKEditor</title>
<!-- Make sure the path to CKEditor is correct. -->
<script src="../ckeditor.js"></script>
</head>
<body>
<form>
<textarea name="editor1" id="editor1" rows="10" cols="80">
This is my textarea to be replaced with CKEditor.
</textarea>
<script>
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace( 'editor1' );
</script>
</form>
</body>
</html>
The galetahub gem is currently broken on Rails 4. This one is working fine though: https://github.com/tsechingho/ckeditor-rails
In case you are having trouble making it work with active admin, make sure to put this:
config.register_javascript 'ckeditor/ckeditor.js'
config.register_javascript 'ckeditor/init.js'
Into config/initializers/active_admin.rb

Wickedpdf Heroku some images are not showing

Everthing works perfect on my local, but on production(Heroku) some images in the generated pdf are not showing:
<img alt="Bg_pdf" id="background" src="file:////app/app/assets/images/bg_pdf.jpg">
<img alt="Bg_pdf2" id="background2" src="file:////app/app/assets/images/bg_pdf2.jpg">
<img alt="Bg_pdf2" id="background3" src="file:////app/app/assets/images/bg_pdf2.jpg">
<img alt="Bg_pdf2" id="background4" src="file:////app/app/assets/images/bg_pdf2.jpg">
<img alt="Step_4" id="pic3" src="file:////app/app/assets/images/steps/raka/right/step_4.jpg" style="margin-top: 20px;">
The #pic3 does not appear, but all the other images above appear.
Why does pic3 not appear in the generated pdf? Is there because there is some sort of maximum amount of images allowed?
In my gem file:
gem 'wicked_pdf', github: 'mileszs/wicked_pdf'
gem 'wkhtmltopdf-heroku'
And I am using the helper method:
<%= wicked_pdf_image_tag("steps/#{session[:product]}/#{session[:sving]}/step_4.jpg", :id => 'pic3', :style => 'margin-top: 20px;') %>
Some trouble with .jpg, jpeg images, used .PNG images instead and it works well.

Resources