How to center table in prawn? - ruby-on-rails

I have created a table in prawn and wanted to pass the :position option by whih is also documented in the manual but it throws off an Method_missing error. It seems like this parameter doesnt exist anymore. How can I center a table in prawn?

I ran into the same error. Installing from master on Github fixed the issue.
# Gemfile
gem 'prawn', git: 'https://github.com/prawnpdf/prawn.git'
Issue thread on Github

Hope this helps
pdf.table tablename,
:border_width => 0,
:font_size => 11,
:position => :center

whether the PDF generation is from a declared class or within the controller
you need to add the following line to your Gemfile
gem 'prawn-table', '~> 0.2.1'
At the time of writing that is the gem version, this will give you access to the table methods such as position
I used it in this example and it worked
def table_items(chart_data, doc)
table = Prawn::Table.new(table_rows(chart_data), doc, {:header => true})
table.row(0).font_style = :bold
table.position = :center
table.draw
end

Related

Brakeman not skipping Gemfile.lock with --skip-files param

I'm adding Brakeman to a Rails product but I'm running into an issue. I want it to ignore my Gemfile and Gemfile.lock but when I run it with a command like
brakeman --skip-files Gemfile.lock,Gemfile
it's still touching the files. We use other systems to monitor our gems, but is it not possible to ignore the gem files completely? I can use a brakeman.ignore file of course but would prefer not to. Thanks for any assistance.
I believe this is the check to which you are referring:
https://github.com/presidentbeef/brakeman/blob/master/lib/brakeman/scanner.rb#L39-L40
Brakeman.notify "Processing gems..."
process_gems
The process_gems function is defined here:
https://github.com/presidentbeef/brakeman/blob/master/lib/brakeman/scanner.rb#L131-L152
#Process Gemfile
def process_gems
gem_files = {}
if #app_tree.exists? "Gemfile"
gem_files[:gemfile] = { :src => parse_ruby(#app_tree.read("Gemfile")), :file => "Gemfile" }
elsif #app_tree.exists? "gems.rb"
gem_files[:gemfile] = { :src => parse_ruby(#app_tree.read("gems.rb")), :file => "gems.rb" }
end
if #app_tree.exists? "Gemfile.lock"
gem_files[:gemlock] = { :src => #app_tree.read("Gemfile.lock"), :file => "Gemfile.lock" }
elsif #app_tree.exists? "gems.locked"
gem_files[:gemlock] = { :src => #app_tree.read("gems.locked"), :file => "gems.locked" }
end
if gem_files[:gemfile] or gem_files[:gemlock]
#processor.process_gems gem_files
end
rescue => e
Brakeman.notify "[Notice] Error while processing Gemfile."
tracker.error e.exception(e.message + "\nWhile processing Gemfile"), e.backtrace
end
The AppTree::exists? function is defined here:
https://github.com/presidentbeef/brakeman/blob/master/lib/brakeman/app_tree.rb#L82-L84
def exists?(path)
File.exist?(File.join(#root, path))
end
The GemProcessor::process_gems function is defined here:
https://github.com/presidentbeef/brakeman/blob/master/lib/brakeman/processors/gem_processor.rb#L11
...lots of code...
I don't see any code that would skip this functionality if a certain switch is provided to brakeman. It also looks like the AppTree::exists? function does not take into account if a file was provided to the --skip-files option.
Unfortunately, I believe the current answer is that you can not ignore the gem files completely.
You could create a PR to do what you want and see if the Brakeman team includes it in the next build:
https://brakemanscanner.org/docs/contributing/
Let us know if you discover a way to solve your problem.

gem rich don't apperas in Active_admin

I installed gem rich in my Rails 4.1.5 project. I'm using Active Admin. In my file of admin I have this line that calls rich:
f.input :content, :as => :rich, :config => { :height => '200px' }, :label => 'Conteúdo'
But when I open Active_admin, the rich don't appears (should appear right below the first field):
My gemfile:
gem 'rich', :git => 'https://github.com/kreativgebiet/rich.git'
In my application.rb I have this lines:
config.assets.prefix = '/lince/assets'
config.relative_url_root = '/lince'
config.action_controller.relative_url_root = '/lince'
When I try without this lines, rich works fine.
Anyone can help me? I can't understand why this not working.
Thanks.
rich has not been updated in years. I recommend you look at other WYSIWYG editors

Where to put gem configuration

I'm using stw_engine gem to get screenshots of websites. This gem requires to provide own config, but I don't know where it should be put. It gives an error StwEngine error: No api secret defined! if I put it to initializers/stw.rb
StwEngine.config({
# required
:api_key => 'xXXXXXXXXXXXXX',
:private_key => 'xxxx,
#optional use if supported
:size => 'lg',
})
gem page:
https://github.com/sabirmostofa/stw-engin
Try to add this code to initializers/stw_engine.rb. Also, there must be :api_secret => 'xxxxx' instead :private_key

Ruby on Rails : Prawn: Positioning table is not working, getting undefined method 'position='

I am trying to position a table on right side but getting
undefined method 'position='
Here is my sample code:
table data , position: :right do
rows(0).font_style = :bold
cells.style :align => :right
cells.borders = []
end
but as per prawn document http://prawn.majesticseacreature.com/manual.pdf‎ above code should run. Where is the problem?
I just figured it out. The master branch of prawn gem has that fixed.
I added
gem 'prawn', :git => "https://github.com/prawnpdf/prawn.git", :ref => '8028ca0cd2'
instead of
gem 'prawn'
Now its working and the code matches with the manual they provided

FasterCSV (seemingly) not working in Rails 3.0.5

I am trying to export data from a rails app and have the user download a CSV file when they hit a certain controller#action.
I found this article and used the sample code exactly.
http://oldwiki.rubyonrails.org/rails/pages/HowtoExportDataAsCSV
I do, in fact, get a CSV file, but within it, there is only one line of output:
#<Proc:0x00000001032c6808#/PATH_CRAP/app/controllers/reports_controller.rb:35>
Here are lines 35, 36 and 37 from the file in question.
render :text => Proc.new { |response, output|
csv = FasterCSV.new(output, :row_sep => "\r\n")
yield csv
I am using Rails 3.0.5 and added the following to my Gemfile:
gem 'fastercsv'
What gives?
render :text => proc {...} does not work in Rails 3. For the replacement, see this question.

Resources