Read my latest article: 8 things I look for in a Ruby on Rails app (posted Thu, 06 Jul 2017 16:59:00 GMT)

Lots of projects to try out

Posted by Mon, 06 Jun 2005 01:41:00 GMT

It will be a few days until we get to see all the applications running on railsday.com A few people have responded to my earlier post with some links to running demos of projects.

Some impressive stuff. :-)

Extending ActionController

Posted by Sun, 05 Jun 2005 17:33:00 GMT

In my pursuit yesterday to make add the desired functionality to ActionController (render string to string), I talked to bitsweat about this and he suggested that I just extend the class in my rails app.

So, I created a file in lib, called action_controller_ext.rb (a shim as he referred to it) and put this in the file:

require 'action_controller'

class ActionController::Base

  def render_string_to_string(text = nil, type = "rhtml") #:doc:
    add_variables_to_assigns
    @template.render_template(type, text) 
  end

end
Then in environment.rb, I changed:
require 'action_controller'
to
require 'action_controller_ext'

Now, I can move my clients app around dev/test/live servers and not need to modify the actual Rails source code. (still would be nice if it did that though)

Playing with Rails Day projects

Posted by Sun, 05 Jun 2005 16:07:00 GMT

Woke up, Rails Day site was down. noradio on irc mentioned that the svn repos were up though. :-)

Earlier this morning, I checked out every Rails Day project and started picking random ones to try to play with. I showed people on #rubyonrails. Of about 30 that I tried to run, I had good experiences with about 5-10. It was surprising to see that a lot of people didn’t put a db schema file in db/. (which prevented me from getting too far)

I am going to tinker with more later, but had to get some of my own work done.

Some of the cool ones that I saw so far were, Sheets, Catfish, fischbowl (spelling), and there was one more but I don’t remember the name. I’ll have to look at them again. I was just picking random project #s and trying… so there are probably lots of them to see. :-)

What were are your favorites so far? project name and #:

odd behavior by typo

Posted by Sun, 05 Jun 2005 11:50:53 GMT

For some reason, Typo seems to be doing something odd with my XML feeds because my RSS Reader is showing duplicates for entries (but this doesnt show up in Typo) and Planet Rails is showing dups now. It not always at the same time, so I am not sure how this is happening.

Any thoughts?

Rendering a ERb template stored in the database to a PDF

Posted by Sat, 04 Jun 2005 21:59:00 GMT

In my PDF generation project, I would like the PDF templates to be stored in the database rather than on the file system. (not everyone who admins the system should have access to the file system).

So, what I did, after playing with all the different render_* methods in Action Controller, was create a new method called render_string_to_string. This marks my first attempt to submit a patch. After doing so, I noticed that Rails trunk included a completely refactored version of action_controller.rb. Perhaps this functionality exists in trunk now, I haven’t had a chance to play with it yet.

However, in the meantime, I can do this:

    letter_template = LetterTemplate.find_by_id(1)

    foo = render_string_to_string(letter_template.body)

    pdf=FPDF.new
    pdf.AddPage
    pdf.SetFont('Times')
    pdf.SetFontSize(12)

    pdf.Write(5, foo)

    pdf.Output


This is the first time that I have started to tinker (all 4 lines) with the actual Rails code base. I’ve wandered around it, but have stuck to using Rails rather than trying to modify it.

If there is a better way to handle this, please let me know. :-)

Ruby FPDF on Ruby on Rails

Posted by Sat, 04 Jun 2005 13:24:00 GMT

3 comments Latest by sg Mon, 21 Aug 2006 08:57:06 GMT

I have been tinkering with Ruby FPDF for a client all night. I found the examples for it to lack in some real-world examples, so I have taken the example from the RubyOnRails wiki and added a bit more to it. I have added things like an image, links and made a generic letter template. (just an example). I didn’t get into the header/footer functions yet, may do that later.

If you are not sure how to use Ruby FPDF, check out the FPDF documentation.

Just download Ruby FPDF and unpack the archive in your libs directory.

To get Railst to load fpdf, I added this to environment.rb:

ADDITIONAL_LOAD_PATHS.concat %w(
  app
  app/models
[..snip...]
  lib/fpdf
).map { |dir| "#{RAILS_ROOT}/#{dir}" }.select { |dir| File.directory?(dir) }
At the top of my controller that uses this lib, I added:
require 'fpdf'

When I browse to this controller/method, I got this PDF to generate with this code.

  def pdf
    send_data gen_pdf, :filename => "robbyonrails-fpdf-test.pdf", :type => "application/pdf"
  end

 private
  def gen_pdf

    d = Date.today

    pdf=FPDF.new
    pdf.AddPage
    pdf.SetFont('Arial')
    pdf.SetFontSize(10)

    pdf.Image('/home/matchboy/logo2.jpg',10,8,86,0,'JPG')

    pdf.Cell(0,6, "PLANET ARGON", 0,1,'R')
    pdf.Cell(0,6, "2802 NE 57th Ave",0,1,'R')
    pdf.Cell(0,6, "Portland, OR 97213",0,0,'R')

    pdf.Ln
    pdf.Ln
    pdf.Write(5, "Jane Doe
123 ABC Street
Gilroy, CA 95020

#{d.month}/#{d.mday}/#{d.year}

Dear Jane Doe,

I just wanted to say...

Epsum factorial non deposit quid pro quo hic escorol. Olypian quarrels et gorilla congolium sic ad nauseum. Souvlaki ignitus carborundum e pluribus unum. Defacto lingo est igpay atinlay. Marquee selectus non provisio incongruous feline nolo contendre. Gratuitous octopus niacin, sodium glutimate. Quote meon an estimate et non interruptus stadium. Sic tempus fugit esperanto hiccup estrogen. Glorious

Cheers,

Robby Russell
          ")
    pdf.Ln
    pdf.Cell(0,6, "PLANET ARGON", 0,1,'L',0,'http://www.planetargon.com/')
    pdf.Output
  end

Once again, the output. (click to view PDF)

It’s nothing special, but it’s just an example of how you can add a bit more than ‘Hello World’ to the top of a PDF. I’m still working on figuring out all the x/y stuff. Maybe I will post a better tutorial in the future with headers and footers.

Until then… have fun!

Older posts: 1 2 3 4