<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Andreas Happe &#187; ruby on rails</title>
	<atom:link href="http://snikt.net/index.php/tag/rails/feed" rel="self" type="application/rss+xml" />
	<link>http://snikt.net</link>
	<description>Vi veri ueniversum vivus vici</description>
	<lastBuildDate>Tue, 06 Jul 2010 21:54:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Provenance on Rails</title>
		<link>http://snikt.net/index.php/2010/04/29/provenance-on-rails-2</link>
		<comments>http://snikt.net/index.php/2010/04/29/provenance-on-rails-2#comments</comments>
		<pubDate>Thu, 29 Apr 2010 19:02:10 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Provenance]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[University]]></category>
		<category><![CDATA[master thesis]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://snikt.net/?p=802</guid>
		<description><![CDATA[First of all, what is provenance? The common description is that provenance describes how an object came into its current state. Think of it as versioning on crack: in addition to performed changes it also detects how and by whom those changes were performed. ..but do I need it? Well that depends: do you have [...]]]></description>
			<content:encoded><![CDATA[<h1><span style="font-weight: normal; font-size: 13px;">First of all, what is provenance? The common description is that <em>provenance describes how an object came into its current state</em>. Think of it as versioning on crack: in addition to performed changes it also detects how and by whom those changes were performed.</span></h1>
<h2>..but do I need it?</h2>
<p>Well that depends:</p>
<ul>
<li>do you have any objects in whose alteration history you&#8217;re interested in? Think about any financial or business object.</li>
<li>social network app? think automatic activity feeds..</li>
<li>do you have any analysis workflow that produces a single output from multiple input data points? Provenance can retroactively create the relationships between the input and output datums.</li>
<li>do you want to monitor a given object&#8217;s access patterns temporary? Think debugging.</li>
</ul>
<p>Actually, the longer you think the more use cases appear.</p>
<p>After the break I&#8217;ll talk about my master thesis (that dealt with provenance), the corresponding RoR prototype and future plans w.r.t. provenance within Ruby on Rails.</p>
<p><span id="more-802"></span></p>
<h2>Background Information</h2>
<p>I&#8217;ve spend some time with<a href="http://snikt.net/wp-content/provenance/master_thesis.pdf"> my master thesis</a> focusing on provenance. It&#8217;s academic so do not expect readability or real-world usability. For that there&#8217;s a <a href="http://www.snikt.net/wp-content/provenance/short_paper.pdf">short paper detailing the rails prototype</a>, an additional use case was detailed<a href="http://snikt.net/wp-content/provenance/genesis.pdf"> in another paper</a>. All source code can be found on <a href="http://github.com/andreashappe">github</a>, it might take some days to get the newest versions into the repositories.</p>
<p>My basic idea was that developers do not want to deal with the details of provenance gathering or storage. They should focus upon their domain application. I developed a system that allowed automatic provenance capturing (through a rails plugin), networked storage and dedicated network query facilities.</p>
<p>The prototype did work, unobtrusive provenance capturing is perfectly possible in Ruby on Rails.  Why do I believe that the master thesis prototype is not perfectly suited for real-world applications? Well,</p>
<ul>
<li>storage was done through a separated RDF graph engine, encapsulated within an <a>own RoR application</a>. This is well suited for large academic test applications but I believe that something using an embedded storage solution (thus easier to integrate within existing systems) might be better suited for Rails.</li>
<li>provenance queries had to be done through SPARQL or a special (easy) REST-based interface. An interface directly integrated within Ruby would be preferable.</li>
<li>It&#8217;s all still Rails 2.3 based. I&#8217;ve finished the prototype some time ago and did work the last months mostly on the documentation. So the prototype should be forward-ported to Rails 3.0.0beta3.</li>
</ul>
<h2>Towards a bright new future!</h2>
<p>So I have finally finished my master thesis and would need a embeddable provenance solution for one of my side-projects. I will base it upon the work done during my master thesis but it will differentiate in various points:</p>
<ul>
<li><em>use embedded storage</em>. Application developers should be able to install the plugin, call a rake task and enjoy the benefits of automatic provenance gathering. Does anyone know a good ruby only RDF/graph engine?</li>
<li>no more special query language.. users should not have to learn a new query language nor interfaces. Provenance should be be provided through virtual <em>ActionModel</em> methods and act as &#8216;normal&#8217; object methods.</li>
<li>update the plugin to work with Rails 3.0, investigate <em>Rack</em> and <em>ActionModel</em></li>
<li>keep the plugin as simple as possible.. so other people can play with it too.</li>
</ul>
<p>I&#8217;m not perfectly sure when my side-project will need need that functionality (or if it even gets towards that point), but if you&#8217;re interested in provenance on rails just <a href="http://github.com/andreashappe/provenance-on-rails-sensor">watch the repository</a> or, even better, branch it and get involved..</p>
]]></content:encoded>
			<wfw:commentRss>http://snikt.net/index.php/2010/04/29/provenance-on-rails-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating PDFs from Ruby on Rails</title>
		<link>http://snikt.net/index.php/2010/03/03/generating-pdfs-from-ruby-on-rails</link>
		<comments>http://snikt.net/index.php/2010/03/03/generating-pdfs-from-ruby-on-rails#comments</comments>
		<pubDate>Wed, 03 Mar 2010 12:25:45 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[adobe pdf]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[prawn]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[wicked_pdf]]></category>
		<category><![CDATA[wkthmltopdf]]></category>

		<guid isPermaLink="false">http://snikt.net/?p=491</guid>
		<description><![CDATA[The problem Ruby on Rails provides various helpers for generating dynamic web content but sometimes you need documents that users can easily store and share between them. The ubiquitous file format for this is Adobe PDF nowadays. The common solution fro this problem is Prawn [github, introduction]. Alas it requires a custom DSL for document description, no [...]]]></description>
			<content:encoded><![CDATA[<h2>The problem</h2>
<p><a href="http://rubyonrails.org/">Ruby on Rails</a> provides various helpers for generating dynamic web content but sometimes you need documents that users can easily store and share between them. The ubiquitous file format for this is <a href="http://en.wikipedia.org/wiki/Adobe_PDF">Adobe PDF</a> nowadays.</p>
<p>The common solution fro this problem is Prawn [<a href="http://wiki.github.com/sandal/prawn/">github</a>, <a href="http://railscasts.com/episodes/153-pdfs-with-prawn">introduction</a>]. Alas it requires a custom DSL for document description, no existing Rails views or partials can be reused. An alternative is <a href="http://www.princexml.com/">princeXML</a> which transforms HTML/CSS into pdf through an external binary. This would allow reuse of existing templates and knowledge (think CSS designers) but has the downside of its price tag of $3800.</p>
<h2>The solution</h2>
<p>Enters <a href="http://github.com/mileszs/wicked_pdf">wicked_pdf</a>: it utilizes <a href="http://code.google.com/p/wkhtmltopdf/">wkhtmltopdf</a> to create a PDF document from a Rails HTML template. HTML rendering is done through the well-known webkit-engine. This allows developers to do PDFs in the right way™: define the document&#8217;s structure through a simple HTML document and theme them through CSS. You&#8217;ll get the automatic benefit of themability: exchange the CSS and you have another format. There are also lots of CSS artists out there that can supply you with different designs.</p>
<p><span id="more-491"></span></p>
<p>I&#8217;ve used this solution with a test Ruby on Rails 3.0-beta application, the steps involved were:</p>
<h3>Install <em>wkhtmltopdf:</em></h3>
<p><strong><span style="font-weight: normal; font-size: 13px;">This program will convert the HTML into the PDF format. To make it work you&#8217;ll need at least version 0.9 which isn&#8217;t installed in Ubuntu 9.10 by default. Just download the <a href="http://code.google.com/p/wkhtmltopdf/downloads/list">static compiled version</a> from the <a href="http://code.google.com/p/wkhtmltopdf/downloads/list">wkhtmltopdf website</a> and place it under <em>/usr/local/bin</em>. </span></strong></p>
<h3>Install the wicked_pdf plugin:</h3>
<p>Just install it in the usual Rails way:</p>
<pre>git submodule add ﻿git://github.com/mileszs/wicked_pdf.git vendor/plugins/wicked_pdf</pre>
<p>Additionally a sample configuration file is needed. You could use the plugin&#8217;s generator script for it but alas this didn&#8217;t work for me with Rails 3.0. Let&#8217;s just copy it form the plugin&#8217;s directory into config/initializers.</p>
<pre>$ cp vendor/plugins/wicked_pdf/generators/wicked_pdf/templates/wicked_pdf.rb config/initializers</pre>
<p>and alter the wkhtmltopdf path within it:</p>
<pre>  WICKED_PDF = {
       :exe_path =&gt; '/usr/local/bin/wkhtmltopdf-amd64'
  }</pre>
<h3>﻿﻿Add pdf instructions to your controller..</h3>
<p>For example I&#8217;m using the <em>invoice#index</em> action to render a simple PDF document.</p>
<pre>  format.pdf do
          @example_text = "some text"
          render :pdf =&gt; "file_name",
                 :template =&gt; 'offers/show.pdf.erb',
                 :layout =&gt; 'pdf',
                 :footer =&gt; {
                    :center =&gt; "Center",
                    :left =&gt; "Left",
                    :right =&gt; "Right"
                 }
  end</pre>
<p>We are rendering the view with a predefined footer containing some sample &#8220;center&#8221;, &#8220;left&#8221; and &#8220;right&#8221; strings. The <em>render :pdf</em> call has various options which can be seen on the wicked_pdf homepage.</p>
<h3>.. and create PDF templates</h3>
<p>The other half of the PDF templates is the view code consisting of a special layout and template for pdf generation.</p>
<p>The layout (<em>app/views/layouts/pdf.html.erb</em>) resembles a normal Ruby on Rails layout file:</p>
<pre>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  &lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
    &lt;%= wicked_pdf_stylesheet_link_tag "pdf" %&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id="content"&gt;
      &lt;%= yield %&gt;
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
<p>The view code should not be too surprising, just place it under <em>app/views/offers/index.pdf.erb</em> :</p>
<pre>&lt;div id="someid"&gt;&lt;%= @example_text %&gt;&lt;/div&gt;</pre>
<p>Lets also create a simple CSS file (<span style="font-style: normal;"><em>public/stylesheets/pdf.css</em></span><span style="font-style: normal;">):</span></p>
<pre>#someid {
  margin-left: 430px;
  display: float;
  height: 150px;
  background-color: green;
  width: 250px;
}</pre>
<p><span style="font-style: normal;"> </span></p>
<p>This is the whole rendering code.</p>
<h3>Reference the PDF view and download it</h3>
<p><span style="font-style: normal;">We still need a reference to the newly created rendernig link, we can easily create this through:</span></p>
<pre><span style="font-style: normal;">link_to 'Create PDF document', invoice_path(@invoice, :format =&gt; :pdf)</span></pre>
<p><span style="font-style: normal;">When the link is clicked a pdf document will be generated and downloaded.</span></p>
<h2>Conclusion</h2>
<p>wicked_pdf allows easy pdf generation in a very Ruby on Rails&#8217; way. It&#8217;s free, it works and is easy to employ..</p>
<p><span style="font-style: normal;">..but not everything is perfect within the wicked_pdf world, especially error handlnig is lacking sometimes. When you&#8217;ve debugging initial problems you can expect the only error feedback to be a HTTP return code of 406. Just start with limited controller (rendering) options and double check that you&#8217;ve referenced the right view and layout paths and you should be fine.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://snikt.net/index.php/2010/03/03/generating-pdfs-from-ruby-on-rails/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails vs. Java, part 1</title>
		<link>http://snikt.net/index.php/2008/02/17/ruby-on-rails-vs-java-part-1</link>
		<comments>http://snikt.net/index.php/2008/02/17/ruby-on-rails-vs-java-part-1#comments</comments>
		<pubDate>Sun, 17 Feb 2008 17:05:38 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://happiness-is-slavery.net/index.php/2008/02/17/ruby-on-rails-vs-java-part-1</guid>
		<description><![CDATA[One of the components of the system developed here at Blackwhale is an fairly advanced web mail/campaigning and analytics system. The first iteration of that component was fully implemented in Ruby on Rails. Writing the front end was fairly easy and fast, a perfect opportunity for Rails to display its strengths. On the back end [...]]]></description>
			<content:encoded><![CDATA[<p>One of the components of the system developed here at <a href="http://www.blackwhale.net">Blackwhale</a> is an fairly advanced web mail/campaigning and analytics system. The first iteration of that component was fully implemented in <a href="http://www.rubyonrails.org">Ruby on Rails</a>. Writing the front end was fairly easy and fast, a perfect opportunity for Rails to display its strengths. On the back end and communication part on the other hand I stumbled into various problems:</p>
<ul>
<li>Compared to PHP, Python or Java there are just too few communication libraries. And even the libraries that exist are lacking fundamental features and almost all of them come without useable documentation. That there is no encryption (SSL or TLS) support in the whole Ruby 1.8 mail libraries is an outright shame. The IMAP library is so clumsy that a web company sells their own (still not perfect library) through their online store and they seem to make a good buck with it.
<p>On the Java side is just a completly different picture: Lots of libraries, even documented ones are available. After having to touch the <a href="http://tmail.rubyforge.org/">TMail</a> (rail&#8217;s MIME mail handler library) API using javax.mail is a heavenly gift. And it seems that the TMail generated MIME messages were invalid in a couple of cases. Not the best feature of a support library. Also the chance of finding unsolved known bugs and errors seems to be lot smaller in Java.</li>
<li>This brings me to another point: I might change my opinion on Java&#8217;s constraints on its users. Java tries hard to prevent errors (i.e. the forced exception catching). I always thought that that took too many stylish possibilities away from the user, but by now I must confess that I think that this is exactly what I want from something that I&#8217;m using on the network side. I&#8217;m a lazy programmer, I want to be reminded and forced to write secure and stable code. This is the quite different to Ruby and Rails &#8216;make it easy for the programmer&#8217; attitude.</li>
<li>Background processing is hard. As Ruby on Rails is not multi-thread safe you can&#8217;t just spawn a thread if you need to perform some longer running task. Another disadvantage of using a single-process model is that the long running request will occupy one rails worker (i.e. rails cluster process) until it has finished &#8211; in our case that costs us around 60MB of memory per long running request, even if it is just waiting for some simple SMTP feedback. If you can find a situation where you can delay the execution of a network related task (and if you don&#8217;t you&#8217;re not thinking) for two seconds, 6 requests per seconds will DoS a standard rails cluster.
<p>The only solution that&#8217;s actually usable is <a href="http://backgroundrb.rubyforge.org/">BackgroundRb</a>. But projects that just change their background communication system just don&#8217;t sound to production-grade ready for me. Also the admin start/stop scripts for their background server didn&#8217;t work too well for me.</li>
<li>For a language that interferes it&#8217;s object&#8217;s attribute types directly from the database the ActiveRecord layer is weak. Don&#8217;t get me wrong, I understand that the Simplicity is needed to make it easily usable but I ran into various situations where I&#8217;d love to have a full blown ORM behind me. One feature that is needed quite often by our application is inheritance. ActiveRecord only offers single table inheritance, and even there you have to make sure that each row is valid (ActiveRecord should have all needed information to do that by itself BTW) or you will run into problems later on. One problem is, that it tries to abstract too much functionality away from the database while not provided as advanced interfaces by itself. Data integrity handling? Abstracted away by rails, so all databases can be used the same. The drawback is, that the data constraints and relations are fully handled by rails and not passed on to the database. Any process that might produce invalid data (e.g. a faulty rails component) might corrupt the data. Rails is able to handle that cases by itself (due to ducktyping and very few default checks), but access that data with any other framework and it blows up directly into your face.</li>
<li>Transaction handling. Just try it. Then cry. Also I&#8217;m not sure if Transaction handling is even done on database level or in Rails (as done with constraints). If the later is true, it&#8217;s acutally not worth anything as soon as more processes try to access the database.</li>
</ul>
<p>The library and documentation problems where the main reason for me to reimplement the mailing and campaigning backend in Java. The front end is still a Rails application &#8212; which is exactly what Rails is for. As I&#8217;m no friend of blown-up EJB based solutions I&#8217;ve choosen a simple Spring and JPA based solution for that problem.</p>
<p>I&#8217;m currently testing the last features and replacing the Ruby code part by part. As soon as I&#8217;ve done that another blog post will examine the two implementations, how much time was spent on coding them and how they perform when compared to each other.</p>
]]></content:encoded>
			<wfw:commentRss>http://snikt.net/index.php/2008/02/17/ruby-on-rails-vs-java-part-1/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
