I get the following error for the code below: undefined method 'rowspan=' for #<Prawn::Table::Cell::Text:0x9477540>
table [
[{content: "<b>control</b>", rowspan: 2},
{content: "time", colspan: 2},
"order",
{content: "count", colspan: 6}]
], cell_style: {size: 10, inline_format: true}
I followed the prawn manual, and can not see what I did wrong. I am using prawn 0.12.0.
According to the Prawn google group, colspan and rowspan were not introduced until a later release. https://groups.google.com/forum/#!searchin/prawn-ruby/rowspan/prawn-ruby/G-QHFUZheMI/3a4pNnLur0EJ
Updating to the lastest master gem from github worked for me:
git clone https://github.com/prawnpdf/prawn.git
Create a directory to test the manual example.
Run bundle init to create a Gemfile in that directory and add this line
gem 'prawn', :path=>'/path/to/your/local/prawn/git/clone/dir'
Create the span_example.rb file from the manual, and set it up to use bundler Gemfile like this:
require 'rubygems'
require 'bundler/setup'
Bundler.require
pdf = Prawn::Document.generate('span_example.pdf') do
table([
["A", {content: "2x1", colspan: 2}, "B"],
[{content: "1x2", rowspan: 2}, "C", "D", "E"],
[{content: "2x2", colspan: 2, :rowspan => 2}, "F"],
["G", "H"]
])
end
Then run
bundle install
ruby span_example.rb
open span_example.pdf
Viola!
Related
I'm currently using Capybara / Poltergeist with PhantomJS. Is there any way to get files that were downloaded by the 'browser' using this setup (e.g. that would be obtained after navigating to a URI)?
Either the URI of the file or the actual file itself would be great. Thanks in advance!
One of solution is this - http://it.fyber.com/blog/2012/11/29/capybara-poltergeist-and-csv-downloads/
Other is to use CSV Ruby library.
Download CSV File is here.
id,name,note
1,name1,note1
2,name2,note2
3,name3,note3
And, your spec file
require 'csv'
feature "Products", :type => :feature do
describe "Download CSV" do
# ... click csv download button by Capybara
rows = CSV.parse(page.body, :row_sep => "\r\n", :force_quotes => true)
# [["id", "name", "note"], ["1", "name1", "note1"], ["2", "name2", "note2"], ["3", "name3", "note3"]]
# assert csv header
header = rows[0]
expect(header).to eq ["id", "name", "note"]
# assert csv rows
# it's better to define expected csv rows and use `each` method
expect(rows[1]).to eq ["1", "name1", "note1"]
expect(rows[2]).to eq ["2", "name2", "note2"]
expect(rows[3])>to eq ["3", "name3", "note3"]
end
end
I have correct code, but Prawn complains to it:
class MyClass < Prawn::Document
# ....
def def123
table main_table , width: bounds.width
end
def main_table
[[
"0","1", "2", "3", "4"
]] +
[
[{content: "data1", colspan: 4}, "111"],
[{content: "data2", colspan: 4}, "222"],
[{content:"data3", colspan: 4}, "333"]
]
end
end
by saying:
undefined method colspan= for Prawn::Table::Cell::Text:0x007fb86c3e7020
Note that I need to use width: bounds.width to be able to make the table fill a whole page.
prawn (0.12.0)
I'd recommend updating your Gem file to pull prawn directly from the git repository. Most undefined method errors are the result of using an out of date version:
gem 'prawn', :git => "https://github.com/prawnpdf/prawn.git"
Following up on this 1 year old post:
Mongodb mongoid model attributes sorted by alphabetical order not insertion order
I have a rails 3.2.8 application that uses mongoid v. 3.0.0. My application occasionally uses the "update_attribute" function on a database object (e.g. a product), but when it does all attributes gets reordered alphabetically.
When I duplicate this in the console, it looks like this:
1.9.3-p385 :001 > product = Product.find("5156bc9b83c3368121000008")
=> [#<Product _id: 5156bc9b83c3368121000008, _type: nil, product_number: "123", product_name: "Some product name", long_description: "<P>Some long product description.</P>", vendor_number: "abc", language_i_d: "1234", currency_i_d: "USD", category_number: "1", image_link: "http://some-external-website.com/image-path.jpg", original_id: "123456">]
1.9.3-p385 :002 > product.update_attribute(:image_link, "http://my-own-website.com/image-path.jpg")
=> true
1.9.3-p385 :003 > exit
I now fire up the console again (for some reason I need to exit and re-open the console before the new order is displayed):
1.9.3-p385 :001 > product = Product.find("5156bc9b83c3368121000008")
=> [#<Product _id: 5156bc9b83c3368121000008, _type: nil, category_number: "1", currency_i_d: "USD", image_link: "http://my-own-website.com/image-path.jpg", language_i_d: "1234", long_description: "<P>Some long product description.</P>", original_id: "123456", product_name: "Some product name", product_number: "123", vendor_number: "abc">]
Does anyone know how to avoid this reordering?
This isn't mongoid's fault. If an update causes a document to grow and mongo had to move the document as a result then mongodb itself may reorder the document's fields (see docs and a jira issue where this is described as normal)
I follow the link GitHub gem rich to install CKeditor to rails_admin
but I get the error: Unsupported field datatype: rich_editor
My model
edit do
field :title
field :description, :rich_editor do
config({
:insert_many => true
})
end
field :autho
field :book_type
end
How can I fix this error? Or that's an issue?
EDIT:
I tried it, and it worked
field :content, :text do
ckeditor do true end
end
I couldn't get the Rich gem to work with a Rails 4 project using Rails admin, so I decided to use the standard CK Editor Gem which is the recommended course of action by the authors. It took all of 5 minutes to get it working following this:
https://github.com/sferik/rails_admin/wiki/CKEditor
Then I configured my CK_Editor to use a small subset of the available functionality.
After adding the CK_Editor gem and configuring my rails admin initializer, I created a new javascript file in my project at:
/app/assets/javascripts/ckeditor/config.js
with the following contents:
CKEDITOR.config.toolbar = [
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ],
items: [ 'Bold', 'Italic', 'Underline', 'Strike', '-', 'RemoveFormat' ] },
{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ],
items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote',
'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock' ] },
{ name: 'links', items: [ 'Link', 'Unlink' ] },
];
Remember to restart your Rails server!
I have the same issue. I think it is an issue in rails_admin or in rich. I have successfully integrate these two together in past (but with old versions of both).
I have created github issues for this in rich (https://github.com/bastiaanterhorst/rich/issues/80) and rails_admin (https://github.com/sferik/rails_admin/issues/1585) repos.
How is this possible?
Loading development environment (Rails 2.3.8)
>> wq = Wq.first(:conditions =>['widget_id=? AND qs_id=?',1,1])
=> #<Wq id: 1, widget_id: 1, qs_id: 1, operator: 0, requirements: "2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2", changes: "1", route: 2, created_at: "2010-09-07 08:11:05", updated_at: "2010-11-24 10:25:53", body: "Which specific area of gyt are you aiming to addres...", options: "['xyz','pqr']", input_type: nil, status: 1>
>> wq.changes
=> {}
>> wq.changes
=> {}
>> wq.requirements
=> "2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2"
>> wq.changes
=> "1"
Why is wq.changes coming as null initially and then after logging wq.requirements, wq.changes seems to come fine?
All necessary fields that are being fetched are withing a attr_accessible in the model.
I am not able to understand this situation, please help all you rails gurus.
The attribute name 'changes' conflicts with the AR::Dirty functionality. You should probably pick a different name for that column.
Here's the rails3 api docs for Dirty:
http://api.rubyonrails.org/classes/ActiveModel/Dirty.html
In rails2 it's in ActiveRecord rather than ActiveModel.
If you aren't able to rename the column, you could work around the issue by calling #model_obj[:changes] instead.
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/base.rb#L1466