I want to create an invoice in PDF format using rails/ruby.
So company header and the top, client information, and then line items with pricing and then a total at the bottom etc.
What do you guys advise?
Is it tricky to get the formatting correct so it prints out correctly?
I recommend a gem called prawn:
http://prawn.majesticseacreature.com/
I've used it before and liked the results.
There is this great alternative oo:
http://railscasts.com/episodes/220-pdfkit
Related
I'm trying to build a website that users create contents of a table and display them. I'm using Ruby on Rails to work on this project. So far I can let users create new rows and display, which is nearly a default function when building an application.
However, I need to know how to limit the number of rows, let's say 15 rows at once, then a user needs to click next button or navigation number (ex, 1,2,3...5) to call next 15 rows of data in the table.
I'm not really sure how to approach this matter.
If I can help on this, that would be a great help.
Thanks!
The easiest way to do what you want is with pagination. There are a number of gems which offer this but I find kaminari the most robust and flexible of these.
Install the Kaminari Gem
https://github.com/kaminari/kaminari -- Add to you gemfile and run bundle install
gem 'kaminari'
Call the Kaminari method in the controller
In your controller, make sure the object collections uses the kaminari method.
#model = Model.all.order(:name).page(params[:page]).per(15)
This is most likely pretty obvious, but just for clarity: The order by is not required for kaminari, the page method will take the parameters from the URL (params are added to the URL when a user clicks on a certain page number or clicks next or prev), and the per method is the number of records allowed on each page.
Add pagination to your view
Now in your view - just call the pagination helper with your object to add the pagination links (Prev 1 2 3 4 5 Next)
= paginate #model
You can also change the look and feel the pagination links, just read the documentation, it's pretty straighforward.
Since this is your first post I will also add:
WELCOME!! Thanks for your post. New questions keep the community on their toes.
Next time you post, keep in mind that everyone here is happy to help, but if you add a few things to your post the answers will come quicker and you won't be downvoted:
Add code snippets and samples to your post, its easier for answers to come if they can see your work and also improves answers if they can mock up code responses based on your original question, less confusion that way
Give links to tutorials you might be using
State what you've tried, and why it's not working as you'd expect / prefer
I would like to create a XPages form to print it out. I am not sure which is the best way to do this. I mean I need to create a panel or table or any other design elements then put all my staff in it?
I need advise:)
Regards
Cumhur Ata
Speak after me: browsers don't print.
If you need precision layout a browser is your worst enemy. Each one renders slightly different, so don't bother.
Your best bet is to create a PDF file for printing. There you have pixel-perfect rendering as you deem fit.
You can use iText, PDFBox or XSL:FO to generate PDF. There are code samples on OpenNTF or you read my blog entries about it.
I am building a simple invoice application, and I would like to allow the users to customize the text on the invoice. In addition to this, they should be able to reference specific attributes in my models, i.e. "This is a test {{Model.attribute}}", and once the text is parsed the tag is replaced with the value of that attribute.
I have looked a bit at redcloth, textile and handlebars, but it does look like a little bit overkill to be honest. For instance I would not like to allow the users to input any HTML.
I would really appreciate if someone could point me in the right direction. There is probably a gem for this that I just havent found yet.
Thanks in advance
I use liquid with simpleformat which will sanitise the text.
Hey guys this has been tripping me up quite a bit. So here is the general problem:
I am writing an application that requires users to enter their Summoner Names from league of legends. I do a pretty simple data scrape of a match and enter the data into my database. Unfortunately I am having some errors registering users with "special characters".
For this example I will use one problem user: RIÇK
As you can see RICK != RIÇK. So when I do the data scrub from the site I get the correct value which I push onto an array for later use.
Once I need the player names I pull from the array as follows: (player_names is the array)
#temp_player = User.find_by_username(player_names[i].to_s)
The problem is the users with any special characters are not being pulled. Should I not be using find_by? Is to_s changing my original values? I am really quite lost on what to do and would greatly appreciate any help / advice.
Thanks in advance,
Dan
I would like to thank Brian Kung for the link to the following: joelonsoftware.com/articles/Unicode.html It does a great job giving the bare minimum a programmer truly needs to understand.
For my particular issue I had used a HTML scraper to get the contents but which kept HTML entries throughout. When using these with my SQL lookups it was obvious that things were not being found. In order to fix this I used the HTMLEntities Gem to decode the text as follows (as soon as I put the into the array originally):
requires 'RubyGems' #without this cannot include htmlentries as a gem
requires 'HTMLEntries'
coder = HTMLEntries.new
line = '<'
player_names.push(coder.decode(line))
The Takeaway
When working with text and if running into errors I would strongly recommend tracing the strings you are working with to the origin and truly understanding what encoding is being used in each process. By doing this you can easily find where things are going wrong.
i am trying to get access to whitepages using YQL. Unfortunately i don't have much experience with opentables.
I was directed to the whitepages xml file at:
http://github.com/spullara/yql-tables/blob/c63212b2ac9db6feb77ae3cecace51ed52e08c01/whitepages/whitepages.search.xml
Does anyone know how to use this table to extract meaningful information using YQL?
Specifically, I'm not sure how to make a query in YQL using this table to search for a person's name.
Help?
Go to the YQL console http://developer.yahoo.com/yql/console/ and click Show Community Tables. That should make the list on the right much bigger, and will include your table.
have you tried to put
&env=http%3A%2F%2Fdatatables.org%2Falltables.env
at the end of your request?