Hi i am getting the following errors while using wicked_pdf gem in Rails3.
error:
ArgumentError in UsersController#download_pdf
wrong number of arguments (0 for 1)
Rails.root: C:/Site/generate4
Application Trace | Framework Trace | Full Trace
app/controllers/users_controller.rb:6:in `download_pdf'
After clicking on download pdf link the following error is coming.
error-2:
RuntimeError in UsersController#download_pdf
Error: Failed to execute:
["C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe", "--encoding", "UTF-8", "file://C:/DOCUME~1/SUBHRA~1/LOCALS~1/Temp/wicked_pdf20150527-1192-1qf0ac.html", "C:/DOCUME~1/SUBHRA~1/LOCALS~1/Temp/wicked_pdf_generated_file20150527-1192-fijfxt.pdf"]
Error: PDF could not be generated!
Command Error: Loading pages (1/6)
[> ] 0%
[======> ] 10%
Error: Failed loading page file://c/DOCUME~1/SUBHRA~1/LOCALS~1/Temp/wicked_pdf20150527-1192-1qf0ac.html (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: ContentNotFoundError
Please check my code below.
users_controller.rb:
class UsersController < ApplicationController
def index
end
def download_pdf
pdf=WickedPdf.new.pdf_from_string(
render_to_string pdf: "test.pdf", template: "users/test.html.erb", encoding: "UTF-8")
#save_path = 'C:\Site\download_pdf.pdf'
end
end
users/test.html.erb:
<h1>Hello rails</h1>
wicked_pdf.rb:
WickedPdf.config = {
#:wkhtmltopdf => '/usr/local/bin/wkhtmltopdf',
#:layout => "pdf.html",
:exe_path => 'C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe'
}
Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.19'
gem 'sqlite3'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'wicked_pdf'
My requirement is convert HTML to PDF using Rails 3.Please help me to resolve this error and successfully get the PDF file.
Assuming, you are trying to download the pdf file.
see the code below:
#users_controller.rb:
class UsersController < ApplicationController
def download_pdf
pdf = render_to_string(pdf: "test.pdf", template: "users/test.html.erb", encoding: "UTF-8")
send_data pdf
end
end
# Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.19'
gem 'sqlite3'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'wicked_pdf', :github => 'mileszs/wicked_pdf', :branch => 'master'
Please check if it works.
Related
I'm trying to merge two elasticsearch results into one variable, here my code tries...
class SearchController < ApplicationController
def index
end
def advanced
#results = {}
if !params[:fast_search].empty?
#results[:features] = TestCases.search(params[:fast_search]).results
#results[:steps] = Steps.search(params[:fast_search]).results
#results[:examples] = Examples.search(params[:fast_search]).results
else
unless params[:feature].blank?
features = TestCases.search(query: { match: { function: params[:feature] } }).results
features_tag = Steps.search(query: { match: { tags: params[:tags] } }).results
#results[:features] = features + features_tag
end
unless params[:steps].blank? || params[:scenario].blank?
#results[:steps] = Steps.search(query: { match: { scenario: params[:scenario] } }).results
params[:steps].each do |step|
#results[:steps] += Steps.search(query: { match: { steps: step } }).results
end
#results[:steps] += Steps.search(query: { match: { tags: params[:tags] } }).results
end
unless params[:examples].blank?
params[:examples].each do |example|
#results[:examples] += Examples.search(query: { match: { examples: example } }).results
end
#results[:examples] += Examples.search(query: { match: { tags: params[:tags] } }).results
end
unless params[:bug].blank?
#results[:miscs] = StepsMiscs.search(query: { match: { bug: true } }).results
end
end
render "search/index"
end
end
I also try features.merge(features_tag) but no success either.
It's simple, I just need to merge one and more results from the elasticsearch, but I simply don't know how.
Here's my Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# jQuery-Turbolinks
gem 'jquery-turbolinks'
# Mysql
gem 'mysql2'
# Safe Attributes
gem 'safe_attributes'
# Elastic Search
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
gem 'elasticsearch-persistence'
gem 'pry'
#rake
gem 'rake'
#sidekiq
gem 'sidekiq'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console'
end
group :production do
#passenger
gem "passenger", require: "phusion_passenger/rack_handler"
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
And here's obviously the error that I'm getting:
undefined method `+' for #<Elasticsearch::Model::Response::Results:0x0000000d2719f8>
Thanks!
Here after a lot of search, I've found this:
unless params[:steps].blank? || params[:scenario].blank? || params[:tags].blank?
query = Jbuilder.encode do |json|
json.query do
json.match do
json.scenario do
json.query params[:scenario]
end
end
params[:steps].each do |step|
json.match do
json.tags do
json.query step
end
end
end
json.match do
json.tags do
json.query params[:tags]
end
end
end
end
#results[:steps] = Steps.search(query).results
end
This help me to search more than one match on all my models.
I know that catch only the basics, but at the moment is part for what I need and I hope this could help all the others around here with the same issue!
Thanks you all!
Can anyone explain what is happening here? I have this simple class with some static methods, and I want to test them.
yaqueline/build/converters/asciidocconverter.rb
# encoding: UTF-8
require 'asciidoctor'
module Yaqueline
module Build
module Converters
class AsciiDocConverter < Converter
class << self
def matches path
path =~ /\.(asciidoc|adoc|ascii|ad)$/
end
def convert content
html = Asciidoctor.convert content, to_file: false, safe: :safe
html = get_guts_out_of_body html
puts "asciidoc #{html}"
html
end
def get_guts_out_of_body html
if html =~ /<body>/
puts "get guts: #{html}"
return html.match(%r{(?<=<body>).*(?=</body>)})
end
html
end
end # class << self
end # class
end
end
end
and the test in test/build/converters/asciidocconverter_test.rb:
# encoding: utf-8
require 'helper'
require 'yaqueline/build/converters/asciidocconverter'
class TestAsciidocConverter < Test::Unit::TestCase
should "be able to get body html from a document" do
value = %q{SUCCESS}
html = %Q{
<html>
<head>
<title>Hej värld</title>
</head>
<body>#{value}</body>
</html>}
guts = Yaqueline::Build::Converters::AsciiDocConverter.get_guts_out_of_body html
puts "guts was '#{guts}'"
assert value.eql?(guts), "guts was '#{guts}', expected '#{value}'"
end
end
When running the test with
$ rake test TEST=test/build/converters/asciidocconverter_test.rb
The results looks good to me:
Started
get guts:
<html>
<head>
<title>Hej värld</title>
</head>
<body>SUCCESS</body>
</html>
guts was 'SUCCESS'
F
===============================================================================================================================================================================
Failure:
guts was 'SUCCESS', expected 'SUCCESS'.
<false> is not true.
test: AsciidocConverter should be able to get body html from a document. (TestAsciidocConverter)
/Users/mats/src/examples/yaqueline/test/build/converters/asciidocconverter_test.rb:37:in `block in <class:TestAsciidocConverter>'
/Users/mats/src/examples/yaqueline/test/build/converters/asciidocconverter_test.rb:39:in `instance_exec'
/Users/mats/src/examples/yaqueline/test/build/converters/asciidocconverter_test.rb:39:in `block in create_test_from_should_hash'
===============================================================================================================================================================================
but the assertion fails which seems odd to me and I'll need some help.
I'm running ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]
and my Gemfilelooks like
# Add dependencies required to use your gem here.
# Example:
# gem "activesupport", ">= 2.3.5"
gem 'mercenary'
gem 'safe_yaml'
gem 'kramdown'
gem 'colorator'
gem 'pathutil'
gem 'nokogiri'
gem 'sass'
gem 'listen', '~> 3.0'
gem 'asciidoctor'
gem 'tilt'
gem 'erubis'
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "rdoc", "~> 3.12"
gem "bundler", "~> 1.0"
gem "juwelier", "~> 2.1.0"
gem "simplecov", ">= 0"
gem 'rubocop', '~> 0.48.1', require: false
gem 'thin' # or whatever I end up with
gem 'minitest'
gem 'test-unit'
gem 'shoulda'
end
Maybe this helps to realize hat test harness I'm using.
Can anyone see the mistake or explain what's going on?
Cheers
Inspect the types of values being compared. One of them is not a string. (Thus, it can't be equal to a string).
guts = html.match(%r{(?<=<body>).*(?=</body>)})
guts # => #<MatchData "SUCCESS">
guts.to_s # => "SUCCESS"
Basics:
Rails 4
Ruby 2.0
We are stumped with why we can't get Bootstrap Javascript to work on Heroku when it works fine on our dev machine. We had it working with modals, but when we switched to tabs it stopped.
Application.js
//= require analytics
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require turbolinks
//= require_tree
production.rb
Entreuse::Application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
development.rb
Entreuse::Application.configure do
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
config.assets.precompile += %w( .svg .eot .woff .ttf)
gemfile
gem 'rails', '4.0.0'
gem 'sass-rails', '~> 4.0.0'
gem "haml", "~> 4.0.5"
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem "bootstrap-sass", "~> 3.1.1.0"
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
gem 'font-awesome-sass', '~> 4.0.3.1'
group :doc do
gem 'sdoc', require: false
end
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
App on Heroku
http://www.entreuse.com/
Any insights would be much appreciated.
Thanks!
We got this fixed!
The problem was with the analytics
//= require analytics
The error we were getting had to do with the fact that analytics.js.coffee was being included at the top before jQuery was included - it should be at the bottom after jQuery is included. So when it used the dollar sign method at the top of the js file, jQuery hadn't been defined yet.
This post was very helpful:
Rails 4 turbolinks with Google Analytics
I'm trying to push my updated gem to rubygems.com and am getting the following result.
~/dev/V2/V2GPTI (master) $ gem build v2gpti.gemspec
Successfully built RubyGem
Name: v2gpti
Version: 0.2
File: v2gpti-0.2-universal-darwin-13.gem
~/dev/V2/V2GPTI (master) $ gem push v2gpti.gemspec
ERROR: While executing gem ... (Gem::Package::FormatError)
package metadata is missing in v2gpti.gemspec
~/dev/V2/V2GPTI (master) $
The only change that I've made to my gem spec since the last push was to add a parseconfig dependency. Here's my gem spec.
Gem::Specification.new do |s|
s.name = 'v2gpti'
s.version = '0.2'
s.platform = Gem::Platform.local
s.summary = 'Git commands for integration with Pivotal Tracker'
s.description = 'Provides a set of additional Git commands to help developers when working with Pivotal Tracker'
s.authors = ['Ben Hale', 'Jeff Wolski']
s.email = 'jeff#xxxxxxxxx.com'
s.homepage = 'https://github.com/v2dev/V2GPTI'
s.license = 'Apache-2.0'
s.files = %w(LICENSE NOTICE README.md) + Dir['lib/**/*.rb'] + Dir['lib/**/*.sh'] + Dir['bin/*']
s.executables = Dir['bin/*'].map { |f| File.basename f }
s.test_files = Dir['spec/**/*_spec.rb']
s.required_ruby_version = '>= 1.8.7'
s.add_dependency 'highline', '~> 1.6'
s.add_dependency 'pivotal-tracker', '~> 0.5'
s.add_dependency 'parseconfig', '~> 1.0'
s.add_development_dependency 'bundler', '~> 1.3'
s.add_development_dependency 'rake', '~> 10.0'
s.add_development_dependency 'redcarpet', '~> 2.2'
s.add_development_dependency 'rspec', '~> 2.13'
s.add_development_dependency 'simplecov', '~> 0.7'
s.add_development_dependency 'yard', '~> 0.8'
Have I left out something in my gemspec?
Don’t push the gemspec, push the actual built gem:
$ gem push v2gpti-0.2-universal-darwin-13.gem
I am getting an issue trying to execute a command after installing a custom jRuby gem. In the gem I created, the Gemfile looks like below:
source "http://rubygems.org"
gem 'archive-tar-minitar', '~> 0.5.2'
gem 'fastercsv', '~> 1.5.4'
gem 'rake', '~> 0.9.2.2'
gem 'liquid', '>= 2.3.0'
gem 'net-sftp', '>=2.0.5'
gem 'net-ssh', '>=2.3.0'
gem 'jruby-openssl', '>=0.7.5'
gem 'crypt', '~>1.1.4'
gem 'nokogiri', '1.5.2'
and the .gemspec file:
$:.push File.expand_path("../lib", __FILE__)
require "example/version"
require "rake"
Gem::Specification.new do |s|
s.name = "example"
s.version = Example::VERSION
s.platform = 'java'
s.date = '2012-03-30'
s.executables = ["load_csv_to_table"]
s.rdoc_options = ["--charset=UTF-8"]
s.add_dependency('bundler', '~> 1.0')
s.add_dependency('archive-tar-minitar', '~> 0.5.2')
s.add_dependency('liquid', '>= 2.3.0')
s.add_dependency('net-sftp', '>=2.0.5')
s.add_dependency('net-ssh', '>=2.3.0')
s.add_dependency('jruby-openssl', '>=0.7.5')
s.add_dependency('crypt', '~>1.1.4')
s.add_dependency('fastercsv', '~> 1.5.4')
s.add_dependency('json', '~>1.6.6')
s.add_dependency('nokogiri', '1.5.2')
s.files = FileList['lib/**/*.rb', 'bin/*', 'vendor/java/**/*', 'resources/**/*'].to_a
s.require_path = ['lib']
s.required_rubygems_version = ">= 1.3.4"
end
In the bin folder, I created a command called 'example':
#!/usr/bin/env jruby
$:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
require 'example'
require 'pp'
pp "Example!!"
I installed the gem created in my local system with no errors (jruby -S gem install example-0.0.1-java.gem), but I when I try launch the command "example" the command doesn't seem to be found