<?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>Bin-Blog &#187; Ruby on Rails</title>
	<atom:link href="http://www.bin-co.com/blog/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bin-co.com/blog</link>
	<description>Learn about the latest in Web Development - as soon as I do.</description>
	<lastBuildDate>Tue, 13 Oct 2009 18:55:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Error Connecting to MySQL using Ruby on Rails in Linux &#8211; and its Solution</title>
		<link>http://www.bin-co.com/blog/2009/04/error-connection-mysql-ruby-rails-linux-solution/</link>
		<comments>http://www.bin-co.com/blog/2009/04/error-connection-mysql-ruby-rails-linux-solution/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 18:22:52 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ror]]></category>
		<category><![CDATA[troubleshoot]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/?p=249</guid>
		<description><![CDATA[I am currently working on a new Rails project. Its been a while since I worked with rails - so I updated Rails using the command '<code>sudo gem update --system</code>'. I started the inbuilt server and tried to open a page - and to my surprise, I found that <strong class="highlight">Rails is having trouble connecting to the MySQL</strong> server. It was apparent that the <strong class="highlight">mysql gem was missing</strong>. So I tried to install it using the command '<code>sudo gem install mysql</code>'. That failed too - this is the error I got...]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.bin-co.com/blog/wp-content/uploads/2008/05/ruby_logo.gif" alt="Ruby Logo" title="Ruby Logo" width="105" height="109" class="alignnone size-full wp-image-105 intro" align="right" /></p>
<p class="intro">I am currently working on a new Rails project. Its been a while since I worked with rails &#8211; so I updated Rails using the command &#8216;<code>sudo gem update --system</code>&#8216;. I started the inbuilt server and tried to open a page &#8211; and to my surprise, I found that <strong class="highlight">Rails is having trouble connecting to the MySQL</strong> server. It was apparent that the <strong class="highlight">mysql gem was missing</strong>. So I tried to install it using the command &#8216;<code>sudo gem install mysql</code>&#8216;. That failed too &#8211; this is the error I got&#8230;</p>
<pre>Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
        ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/bin/ruby
        --with-mysql-config
        --without-mysql-config
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-mlib
        --without-mlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-zlib
        --without-zlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-socketlib
        --without-socketlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-nsllib
        --without-nsllib
        --with-mysqlclientlib
        --without-mysqlclientlib

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out</pre>
<p>After a couple of hours on Google, I managed to fix the issue &#8211; and I am posting the solution here for others who might run into the same problem.</p>
<h2>Install the necessary Libraries</h2>
<p>First, you must <strong class="highlight">install a couple of mysql libraries</strong>(I am assuming that you have MySQL server already installed). If you are on <strong class="highlight">Red Hat/Fedora/CentOS</strong> etc., run the command&#8230;</p>
<pre><code class="cli">sudo yum install ruby-mysql mysql-devel</code></pre>
<p>If you are on <strong class="highlight">Debian/Ubuntu</strong>/etc., run this command&#8230;</p>
<pre><code class="cli">sudo apt-get install libmysqlclient15-dev libmysqlclient15off libmysql-ruby</code></pre>
<h2>Install the gem</h2>
<p>Once the installation is done, enter this <strong class="highlight">command to install mysql gem</strong>&#8230;</p>
<pre><code class="cli">sudo gem install mysql -- --with-mysql-config=/usr/bin/mysql_config</code></pre>
<p>If your mysql_config is not in the standard location, update the command with the right path.</p>
<p>The mysql gem should be installed now. These commands worked for me &#8211; your milage may vary. If you still have trouble, try one of the following links&#8230;</p>
<h2>More Resources</h2>
<ul>
<li><a href="http://rails.aizatto.com/2007/05/19/connecting-to-mysql-using-ruby/">Connecting To MySQL using Ruby</a></li>
<li><a href="http://wiki.rubyonrails.org/database-support/mysql">MySQL =&gt; Rails Wiki</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2009/04/error-connection-mysql-ruby-rails-linux-solution/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Installing the acts_as_taggable Rails Plugin</title>
		<link>http://www.bin-co.com/blog/2007/12/installing-the-acts_as_taggable-rails-plugin/</link>
		<comments>http://www.bin-co.com/blog/2007/12/installing-the-acts_as_taggable-rails-plugin/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 17:04:58 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[acts_as_taggable]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[tags]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/2007/12/installing-the-acts_as_taggable-rails-plugin/</guid>
		<description><![CDATA[You don&#8217;t have to write a lot of code to get tagging support in your Ruby on Rails application &#8211; you just have to install a plugin. This is how you install the &#8216;acts_as_taggable&#8217; plugin&#8230; First go to the Ruby on Rails application folder and open a terminal at that location. Now run this commad&#8230; [...]]]></description>
			<content:encoded><![CDATA[<p class="intro">You don&#8217;t have to write a lot of code to get tagging support in your Ruby on Rails application &#8211; you just have to install a plugin. This is how you install the &#8216;acts_as_taggable&#8217; plugin&#8230;</p>
<p>First go to the Ruby on Rails application folder and open a terminal at that location. Now run this commad&#8230;</p>
<p><code class="cli">ruby script/plugin install acts_as_taggable</code></p>
<p>If your have previously installed some plugins from the same repository, that command will work. If not, you will get this error&#8230;</p>
<p><code>Plugin not found: ["acts_as_taggable"]</code></p>
<p>This is because the &#8216;acts_as_taggable&#8217; plugin is not in any of the repositories you check. To see the all the repositories on your check list, run this command&#8230;</p>
<p><code>ruby script/plugin list  	#Shows the list of all the repositories you check.</code></p>
<p>To add new repositories to your list, you have to run this command&#8230;</p>
<p><code>ruby script/plugin discover</code></p>
<p>This will shows a list of repositories &#8211; just press &#8216;y&#8217; to select all the repositories you need. I added every repository in the list.</p>
<p>Now run the first command again&#8230;</p>
<p><code>ruby script/plugin install acts_as_taggable</code></p>
<h2>Installing the Gem</h2>
<p>The above instructions are for installing the acts_as_taggable plugin &#8211; not the acts_as_taggable gem. To install the gem run the command&#8230;</p>
<p><code>gem install acts_as_taggable</code></p>
<h2>Related Links</h2>
<ul>
<li><a href="http://wiki.rubyonrails.com/rails/pages/ActsAsTaggablePluginHowto">Acts As Taggable Plugin Howto</a></li>
<li><a href="http://nubyonrails.com/articles/the-complete-guide-to-rails-plugins-part-i">The Complete Guide to Rails Plugins</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2007/12/installing-the-acts_as_taggable-rails-plugin/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Creating PDF in Ruby on Rails &#8211; PDF::Writer</title>
		<link>http://www.bin-co.com/blog/2007/11/creating-pdf-in-ruby-on-rails-pdfwriter/</link>
		<comments>http://www.bin-co.com/blog/2007/11/creating-pdf-in-ruby-on-rails-pdfwriter/#comments</comments>
		<pubDate>Mon, 12 Nov 2007 17:45:18 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Writer]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/2007/11/creating-pdf-in-ruby-on-rails-pdfwriter/</guid>
		<description><![CDATA[PDF::Writer is my choice for creating PDF files in Ruby on Rails. Its simple, easy to use, and has all the features I am looking for.]]></description>
			<content:encoded><![CDATA[<p class="intro">PDF::Writer is my choice for creating PDF files in Ruby on Rails. Its simple, easy to use, and has all the features I am looking for.</p>
<p>Install PDF::Writer in Linux systems using this command&#8230;</p>
<p><code>gem install pdf-writer -y</code></p>
<h3>Includes</h3>
<p>We will require rubygems and pdf/writer.</p>
<pre><code class="ruby">require "rubygems"
require "pdf/writer"
</code></pre>
<p>The next line creates a new instance of PDF::Writer</p>
<pre><code class="ruby">pdf = PDF::Writer.new</code></pre>
<h3>Create a Heading(big font size)</h3>
<pre><code class="ruby">pdf.select_font "Times-Roman"
pdf.text "Sample PDF Document", :font_size => 32, :justification => :center
</code></pre>
<p>The text function will add a string of text to the document, starting at the current position. It will wrap to keep within the margins &#8211; so you can specify text as big blocks. The text will go to the start of the next line when a return code &#8220;\n&#8221; is found.</p>
<p>The other arguments available for this function are&#8230;</p>
<dl>
<dt>:font_size</dt>
<dd>The font size to be used. If not specified, is either the last font size or the default font size of 12 points. Setting this value changes the current font_size.</dd>
<dt>:left</dt>
<dd>Gap to leave from the left margin</dd>
<dt>:right</dt>
<dd>Gap to leave from the right margin</dd>
<dt>:absolute_left</dt>
<dd>Absolute left position (overrides :left)</dd>
<dt>:absolute_right</dt>
<dd>Absolute right position (overrides :right)</dd>
<dt>:justification</dt>
<dd>This can be :left, :right, :center, :full</dd>
<dt>:leading</dt>
<dd>This defines the total height taken by the line, independent of the font height.</dd>
<dt>:spacing</dt>
<dd>Line spacing &#8211; usually set to one of 1, 1.5, 2 (line spacing as used in word processing)</dd>
</dl>
<h3>Writing Text</h3>
<pre><code class="ruby">pdf.text "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam sodales velit ac ante. Suspendisse felis mi, convallis at, semper id, malesuada eu, mauris. Integer orci. Sed consectetuer orci. In hac habitasse platea dictumst. Duis nec pede. Ut lacinia eros ut magna. Maecenas lectus dui, lacinia vel, porttitor a, fringilla nec, turpis. Nulla odio nisi, mattis ac, porttitor at, malesuada ac, nibh. Nam suscipit mi ut justo. Phasellus aliquam lorem non velit ornare bibendum. Nullam mollis. Ut elementum rutrum justo. Pellentesque ac sapien. In facilisis lorem a enim. Curabitur vitae felis. In eget tellus nec ligula egestas semper. Nulla facilisis urna nec magna. Pellentesque fringilla pulvinar risus. Aliquam rutrum, nisi ut lobortis consequat, nisl felis posuere risus, at sollicitudin nibh dui et felis.

Fusce tristique dapibus neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut felis mi, dictum ut, vehicula non, fermentum quis, elit. Quisque ultricies purus quis enim. Integer turpis elit, porttitor quis, volutpat consequat, interdum vitae, quam. Donec tempus, dolor eget bibendum euismod, metus dolor imperdiet purus, vitae nonummy est mi non orci. Aenean eu massa. Fusce euismod. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Nullam quis massa id sem commodo eleifend. Cras eu velit rutrum leo egestas adipiscing. Nulla volutpat, lectus sit amet sagittis gravida, erat tortor condimentum sem, vitae sollicitudin lectus diam eget felis. Aliquam augue. Vestibulum viverra est. Fusce tellus ligula, euismod sed, placerat vel, cursus dictum, erat.", :font_size => 12
</code></pre>
<p>I used the text() &#8211; but this time with 12 as the font_size. The long text will wrap around and the \n will be converted to line breaks.</p>
<h3>Inserting Images</h3>
<p>PDF::Writer provides an easy way to insert images&#8230;</p>
<pre><code class="ruby">pdf.image "default.png"</code></pre>
<p>That&#8217;s it &#8211; it will insert an image called &#8216;default.png&#8217;. The other option are&#8230;</p>
<dl>
<dt>:pad</dt>
<dd>The number of PDF userspace units that will be on all sides of the image. The default is 5 units.</dd>
<dt>:width</dt>
<dd>The desired width of the image. The image will be resized to this width with the aspect ratio kept. If unspecified, the imageâ€™s natural width will be used.</dd>
<dt>:resize</dt>
<dd>How to resize the image, either :width (resizes the image to be as wide as the margins) or :full (resizes the image to be as large as possible). May be a numeric value, used as a multiplier for the image size (e.g., 0.5 will shrink the image to half-sized). If this and :width are unspecified, the imageâ€™s natural size will be used. Mutually exclusive with the <tt>:width</tt> option.</dd>
<dt>:justification</dt>
<dd>The placement of the image. May be :center, :right, or :left. Defaults to :left.</dd>
<dt>:border</dt>
<dd>The border options. No default border. If specified, must be either true, which uses the default border, or a Hash.</dd>
</dl>
<h3>Tables</h3>
<p>Inserting tables are slightly more complicated than the last two items. If you are using SimpleTable, you have to add<br />
<code>require "pdf/simpletable"</code><br />
along with the other includes.</p>
<pre><code class="ruby">table = PDF::SimpleTable.new
table.title = "Sample Tables"
table.column_order.push(*%w(first second))

table.columns["first"] = PDF::SimpleTable::Column.new("first")
table.columns["first"].heading = "First"

table.columns["second"] = PDF::SimpleTable::Column.new("second")
table.columns["second"].heading = "Second"

table.show_lines    = :all
table.show_headings = true
table.orientation   = :center
table.position      = :center

data = [
	{"first"=> "1", "second"=> "2"}, # First row
	{"first"=> "One", "second"=> "Two"}, # Second row
	{"first"=> "Mono", "second"=> "Di"}, # Third row
]

table.data.replace data
table.render_on(pdf)</code></pre>
<p>The above code will create a table with two column and three rows of data. The code should be easy to decipher &#8211; so I am not going into any more explanation.</p>
<h3>Saving the PDF</h3>
<p>Finally, saving the created PDF&#8230;</p>
<pre><code class="ruby">pdf.save_as("report.pdf") </code></pre>
<h2>Links</h2>
<ul>
<li><a href="http://www.artima.com/rubycs/articles/pdf_writer.html">Tutorial</a></li>
<li><a href="http://ruby-pdf.rubyforge.org/pdf-writer/">Website</a></li>
<li><a href="http://ruby-pdf.rubyforge.org/pdf-writer/manual/manual.pdf">Manual (PDF)</a></li>
<li><a href="http://ruby-pdf.rubyforge.org/pdf-writer/doc/index.html">API Documentation</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2007/11/creating-pdf-in-ruby-on-rails-pdfwriter/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

