<?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/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>class Nasir &#60; Jamal</title>
	<atom:link href="http://nasir.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://nasir.wordpress.com</link>
	<description>self.blog(social_network, ruby_on_rails, technology_options = {})</description>
	<lastBuildDate>Thu, 07 Aug 2008 07:04:10 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
		<url>http://www.gravatar.com/blavatar/2d362508bf9c26a7381979c4a4ec5ffa?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>class Nasir &#60; Jamal</title>
		<link>http://nasir.wordpress.com</link>
	</image>
			<item>
		<title>Do I need Stored Procedures? Maybe or Maybe not.</title>
		<link>http://nasir.wordpress.com/2008/07/31/do-i-need-stored-procedures-maybe-or-maybe-not/</link>
		<comments>http://nasir.wordpress.com/2008/07/31/do-i-need-stored-procedures-maybe-or-maybe-not/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 20:34:32 +0000</pubDate>
		<dc:creator>nasir</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[object relational mapping]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[stored procedures]]></category>
		<category><![CDATA[triggers]]></category>

		<guid isPermaLink="false">http://nasir.wordpress.com/?p=44</guid>
		<description><![CDATA[
I have written a couple of posts about 7-8 months back (here and here) on how to call stored procedures from a rails application. After using stored procedures in my app for a while I started to think about whether we really need them. So over a couple of months I discussed it (mainly short [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=44&subd=nasir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fprogramming%2FDo_we_need_Stored_Procedures_Maybe_or_Maybe_not' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe></p>
<p>I have written a couple of posts about 7-8 months back (<a href="http://nasir.wordpress.com/2007/12/03/stored-procedures-and-rails/" target="_blank">here</a> and <a href="http://nasir.wordpress.com/2007/12/04/stored-procedures-and-rails-part-2/" target="_blank">here</a>) on how to call stored procedures from a rails application. After using stored procedures in my app for a while I started to think about whether we really need them. So over a couple of months I discussed it (mainly short discussions about stored procedures not whether to use them or not) with my colleagues, friends, other people  and gave some thought to it. If you are new to stored procedures then here is a sort of textbookish definition.</p>
<p>Stored procedures are available to applications accessing an RDBMS, they are similar to constructs seen in other programming languages and stored in database data dictionary. Stored procedures remove the compilation overhead required for inline queries as they can be pre-compiled, hence they run faster in some cases. However, now most RDBMS, as they evolved, implement statement caches to avoid repetitive compilation of SQL statements.</p>
<p><strong>Why people think we need them?</strong></p>
<p>People, especially with database background or DBAs, are of the view that we should use stored procedures for most of the tasks involving database because they offer following advantages:</p>
<ol>
<li>Stored procedures separate server side function from the client side, i.e, put all your business logic in stored procedures.</li>
<li>Stored procedures are modular and offer advantages compared to embedded queries buried within the GUI code.</li>
<li>They are faster, secure and maintainable</li>
<li>Reduced network usage between clients and servers</li>
</ol>
<p><strong>Why people or I think we don&#8217;t need them?</strong></p>
<ol>
<li>If the application in question even has a remote chance of running on more than one RDBMS then I would just kick stored procedures out of the door because the exact implementation of stored procedure varies from one database system to another and I certainly won&#8217;t like to tie my app to a particular database.</li>
<li>Having business logic in stored procedures is not only breaking every rule of good programming but also not following the tried and trusted way of architecting n-Tier applications, i.e. separating presentation, business logic and storage/data access.  Do not mix storage/data access with logic because stored procedures are just an extension of data access tier. As they say, use database as a very efficient file cabinet. The only concern of a database should be to store data or persistent objects and the business logic should reside in the application code.   Database in itself is not an application you are developing, it’s part of the layer/tier that stores data. We use SQL in RDBMS and SQL is simply a data manipulation language hence very limited in its scope. A programmer can do everything in the application code that can be done in a stored procedure but the opposite of this is definitely not possible. Hence, databases are not programmable enough to include all the business logic. If you somehow manage doing that using temp tables, inserting redundant rows into the tables, by spending &#8216;n&#8217; number of extra hours or other hacks then you are gonna face performance/scalability issues and surely maintenance problems later in the development life cycle, i.e. a nightmarish, incomprehensible &amp; complex POS (piece of shit). These issues will come back persistently to haunt you and your team.  Hence, the advantage 1 and part of advantage 3 mentioned above is not valid anymore.</li>
<li>Storing business logic in the stored procedures also leads to more work for testing compared to having them in (Object Relational Mapping) OR / domain model class and stored procedures/triggers  make test driven development less productive. Also, if I am using ORM then I do not need to use any SQL in my application code because the ORM will generate optimised queries for me on the fly and will also bring simplification and consistency in the coding of whole team. Hence, advantage 2 and part of advantage 3 mentioned above is not valid any more.</li>
<li>Stored procedures can very easily get out of synch with the application code. For instance, if I have different versions of my app in the source code repository and in case something goes wrong with my latest version then I can very easily switch back to an older version by simply checking out / exporting stuff from the repository. But these facilities do not exist for stored procedures / triggers. It&#8217;s troublesome to have business logic residing in stored procedures because they are in the database and once you alter an existing procedure the old one is gone,  hence no going back. Now some of you may argue to keep each stored procedure/trigger in some text file and commit it to the repository with the app but that&#8217;s again creating additional work for your team which means you are also adding chances of error/mistakes. However, if you do this then you still have to run your stored procedures/triggers with every update that&#8217;s again prone to mistake/errors.</li>
<li>When something goes wrong then stored procedures don&#8217;t provide meaningful feedback unless you code all the exception handling within the procedure itself.</li>
<li>You can&#8217;t pass objects to stored procedures. If you are using an ORM, and you have a class that is mapping to a table then you can simply pass the object of that class and you are good but with stored procedures you have to pass each field or object attribute as parameters and you may end up passing lots of them, may be 20, 30,40 or even more. Hence, you end up writing more code which essentially is more error prone and if you get a ‘bad call’ error then go figure what just happened. That’s just creating one object what if you need to add a record to 4 tables simultaneously using transaction and let’s say each of them have 10 fields then you need to pass 40 parameters. Change is the only constant in life, especially in the business environment.  Lets say, due to some business requirement your database schema changes and you have to add/remove columns to/from those tables. If you are using stored procedures then you atleast need to take these steps to make sure that your application is still working fine:
<ul>
<li> Add new data vaildation rules for CRUD operation.</li>
<li>Change the way data presented to users and your form fields where you allow users to create/update records.</li>
<li>Add or remove new parameters to the stored procedure calls from your front end</li>
<li>Add or remove new parameters to your stored procedure definition</li>
<li>Add or remove new parameters to all other stored procedures or triggers from where you are calling your affected stored procedure(s).</li>
</ul>
<p>If you are using ORM instead of stored procedures then you need to take these steps to make sure that your application is OK:</p>
<ul>
<li> Add new data vaildation rules for CRUD operation.</li>
<li>Change the way data presented to users and your form fields where you allow users to create/update records.</li>
</ul>
<p>That&#8217;s it and you will also have your whole app properly version controlled so that you can switch back and forth seamlessly. So why do you want to do something that involves more work leading to delays, increased complexity, less productivity and has more chances of error? Hence, stored procedures/triggers are actually a constraint in your system and according to Theory of Constraints; generally, in any system or process there is one constraint at a time. To improve overall system or process performance first find the constraint then improve it or eliminate the constraint entirely. Do I need to say more?</li>
</ol>
<p>If you think you can use stored procedures to hide business logic,  then you are definitely using stored procedure what it is not good or designed for. I neither like putting SQL queries in my code nor have any problem using stored procedures only if they can offer me/my team/employer some measurable benefits but in my opinion an OR model is much better in terms of developer time, code, productivity and maintenance. Using stored procedures indicates adding another layer, another language, complexity and losing database portability. If I have an application running on ‘n’ number of different clients then it will be much easier for me to keep my application code synchronized and maintainable rather than the stored procedures and triggers. Triggers pose another problem area because application does not know whether they exist hence do not even have a clue whether they have run or not. What if you have some logic in one of your trigger and that itself may be calling another stored procedure(s) (again some logic  on important data) and due to one or the other problem trigger didn’t fire, you are screwed because neither you nor your application will know whether the trigger was fired or not unless your application users see some discrepancy in their data or reports, report them back to you and then you run multiple sql queries and check everything manually. How kewl is that? Not for me atleast.</p>
<p>Having said all that, I don&#8217;t mean the stored procedures were never useful or the advantages of stored procedures cited by DBAs were never true, yes they were true until 6/7 years ago. But with time, new technologies come into existence, some lose their advantages and some become obsolete. There is no point in sticking to something for which you have other better options available.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nasir.wordpress.com/44/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nasir.wordpress.com/44/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nasir.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nasir.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nasir.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nasir.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nasir.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nasir.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nasir.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nasir.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nasir.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nasir.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=44&subd=nasir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://nasir.wordpress.com/2008/07/31/do-i-need-stored-procedures-maybe-or-maybe-not/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/170b5dc385cc9ddf78ed01bcf1e6990a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nasir</media:title>
		</media:content>
	</item>
		<item>
		<title>Formatting/styling will_paginate</title>
		<link>http://nasir.wordpress.com/2008/04/16/formattingstyling-will_paginate/</link>
		<comments>http://nasir.wordpress.com/2008/04/16/formattingstyling-will_paginate/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 09:17:28 +0000</pubDate>
		<dc:creator>nasir</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[formatting pagination links]]></category>
		<category><![CDATA[styling pagination]]></category>
		<category><![CDATA[will_paginate]]></category>

		<guid isPermaLink="false">http://nasir.wordpress.com/?p=43</guid>
		<description><![CDATA[
I received few requests in the past ( personally and recently a comment on my post describing how to use will_paginate plugin ) about how to format pagination links while using will_paginate plugin.
So here it is:
When you add
&#60;%= will_paginate @obj_instance %&#62;
in your views to show your pagination links then it also creates an element (div) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=43&subd=nasir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fprogramming%2FFormatting_Styling_pagination_links_will_paginate' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe><br />
I received few requests in the past ( personally and recently a comment on <a href="http://nasir.wordpress.com/2007/10/31/pagination-in-ruby-on-rails-using-will_paginate-plugin">my post describing how to use will_paginate plugin</a> ) about how to format pagination links while using will_paginate plugin.</p>
<p>So here it is:</p>
<p>When you add</p>
<p><code>&lt;%= will_paginate @obj_instance %&gt;</code></p>
<p>in your views to show your pagination links then it also creates an element (div) and wraps the whole thing under the class name pagination. The one with the current page will have the class name current.</p>
<p>Here is the html code generated by will_paginate</p>
<p><code><br />
&lt;div class="pagination"&gt;<br />
&lt;a href="/page_path?page=2"&gt;« Previous&lt;/a&gt;<br />
&lt;a href="/page_path"&gt;1&lt;/a&gt;<br />
&lt;a href="/page_path?page=2"&gt;2&lt;/a&gt;<br />
&lt;span class="current"&gt;3&lt;/span&gt;<br />
&lt;a href="/page_path?page=4"&gt;4&lt;/a&gt;<br />
&lt;a href="/page_path?page=5"&gt;5&lt;/a&gt;<br />
&lt;a href="/page_path?page=4"&gt;Next »&lt;/a&gt;<br />
&lt;/div&gt;<br />
</code></p>
<p>Now, it is totally upto your imagination how you want to style it using CSS.</p>
<p>But, if due to some reason you don’t want to use the class pagination and add your own then do something like this</p>
<p><code><br />
&lt;%= will_paginate @obj_instance, :class =&gt; 'my_class' %&gt;<br />
</code></p>
<p>Similarly, if you want to add an element id then<br />
<code><br />
&lt;%= will_paginate @obj_instance, :id =&gt; 'my_element' %&gt;<br />
</code></p>
<p>Let&#8217;s say if you have done both like so:<br />
<code><br />
&lt;%= will_paginate @obj_instance, :id =&gt; 'my_element', :class =&gt; 'my_class' %&gt;<br />
</code></p>
<p>then the new html generated by will_paginate will be<br />
<code><br />
&lt;div class="my_class" id="my_element"&gt;<br />
&lt;a href="/page_path?page=2"&gt;« Previous&lt;/a&gt;<br />
&lt;a href="/page_path"&gt;1&lt;/a&gt;<br />
&lt;a href="/page_path?page=2"&gt;2&lt;/a&gt;<br />
&lt;span class="current"&gt;3&lt;/span&gt;<br />
&lt;a href="/page_path?page=4"&gt;4&lt;/a&gt;<br />
&lt;a href="/page_path?page=5"&gt;5&lt;/a&gt;<br />
&lt;a href="/page_path?page=4"&gt;Next »&lt;/a&gt;<br />
&lt;/div&gt;</code><br />
Yes, it is that simple.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nasir.wordpress.com/43/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nasir.wordpress.com/43/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nasir.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nasir.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nasir.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nasir.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nasir.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nasir.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nasir.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nasir.wordpress.com/43/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nasir.wordpress.com/43/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nasir.wordpress.com/43/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=43&subd=nasir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://nasir.wordpress.com/2008/04/16/formattingstyling-will_paginate/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/170b5dc385cc9ddf78ed01bcf1e6990a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nasir</media:title>
		</media:content>
	</item>
		<item>
		<title>SPhred Relaunched</title>
		<link>http://nasir.wordpress.com/2008/04/13/sphred-relaunched/</link>
		<comments>http://nasir.wordpress.com/2008/04/13/sphred-relaunched/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 20:12:43 +0000</pubDate>
		<dc:creator>nasir</dc:creator>
				<category><![CDATA[SP|hred.com]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[openid]]></category>
		<category><![CDATA[restful]]></category>
		<category><![CDATA[sphred]]></category>

		<guid isPermaLink="false">http://nasir.wordpress.com/?p=42</guid>
		<description><![CDATA[SPhred was relaunched last week (1st week of April, 2008) with RESTful interface, new codebase and a new design. Here is a summary of the changes:

Now we have OpenID authentication on SPhred, i.e., new users do not need to Sign Up to use SPhred if they have an Open ID account.
In the past, some users [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=42&subd=nasir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://www.sphred.com">SPhred</a> was relaunched last week (1st week of April, 2008) with <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">RESTful</a> interface, new codebase and a new design. Here is a summary of the changes:</p>
<ol>
<li>Now we have <a href="https://www.myopenid.com/">OpenID</a> authentication on SPhred, i.e., new users do not need to Sign Up to use SPhred if they have an Open ID account.</li>
<li>In the past, some users have suggested that they do not want their full name to be shown on their profile page, so now we do not show any user&#8217;s full name anywhere because we have added nicknames or user names.</li>
<li>I thought its a bit tedious to type your whole email address to login, hence added an option of using the Sign In name, ie.  you can either use your Sign In name or the email address. If you do not know your Sign In name yet then Sign In using your email address and you will see it once you are signed in.</li>
<li>If you have done some activity on SPhred like adding tags to your profile, SPhredding, connected with other people then SPhred can also recommend a network of people with similar interests on SPhred. Simply go to your profile and click on the &#8216;More Like you&#8217; link to check this out.</li>
<li>You can also send short messages to other users by using the &#8216;Buzz&#8217; link on a user profile.</li>
<li>I think it is important to bring the old posts back to users&#8217; attention once in a while even if it has gone past 10th page and hence have implemented a &#8216;Random Picks&#8217; widget which is shown on almost every page. Go to the widgets page <a href="http://www.sphred.com/widgets">http://www.sphred.com/widgets</a> and check out the other widgets.</li>
<li>I received lots of spam in the past, hence now we have <a href="http://en.wikipedia.org/wiki/Captcha">captcha</a> implemented on almost every page where users contribute to SPhred.</li>
<li>Previously, every post on SPhred had a URL like http://www.sphred.com/sphred_details/site_name,  this url scheme is still kept for backward compatibility but now we have better and more meaningful (&amp; RESTful) urls like http://www.sphred.com/categories/1-New-Launches/websites/site_name.NOTE: The old url scheme will be phased out eventually hence can I request you change the old urls on your blogs/websites to the new ones.</li>
<li>There are many more behind the scenes changes and some you will notice in time.</li>
<li>And yes, this is how SPhred looked in the past <a href="http://www.sphred.com/images/sphred.png">http://www.sphred.com/images/sphred.png</a></li>
</ol>
<p>If you have any feedback and suggestion then do send it to me, have fun!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nasir.wordpress.com/42/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nasir.wordpress.com/42/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nasir.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nasir.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nasir.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nasir.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nasir.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nasir.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nasir.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nasir.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nasir.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nasir.wordpress.com/42/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=42&subd=nasir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://nasir.wordpress.com/2008/04/13/sphred-relaunched/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/170b5dc385cc9ddf78ed01bcf1e6990a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nasir</media:title>
		</media:content>
	</item>
		<item>
		<title>Database views and Rails</title>
		<link>http://nasir.wordpress.com/2007/12/17/database-views-and-rails/</link>
		<comments>http://nasir.wordpress.com/2007/12/17/database-views-and-rails/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 04:45:01 +0000</pubDate>
		<dc:creator>nasir</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[database views]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://nasir.wordpress.com/2007/12/17/database-views-and-rails/</guid>
		<description><![CDATA[
When it comes to using database views then most of us think that it is difficult to use them with Rails or we may not be able to use ActiveRecord with it. Since I experimented with it in the past so I thought why not share it with you folks.
There are several situations when we [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=41&subd=nasir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fprogramming%2FDatabase_views_and_Rails' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe></p>
<p>When it comes to using database views then most of us think that it is difficult to use them with Rails or we may not be able to use ActiveRecord with it. Since I experimented with it in the past so I thought why not share it with you folks.</p>
<p>There are several situations when we would like to use database views with our Rails application like:</p>
<p>Situation 1:</p>
<p>If we have a complex SQL query that we don&#8217;t want to code in your Rails app due to performance related or any other issues.</p>
<p>Situation 2:</p>
<p>When our database guys have already spent a great amount of time writing useful views that can be used in the current app</p>
<p>Situation 3:</p>
<p>When we have some repeated query to run in every select statement to fetch data from every table. For instance<br />
<code>Select * from table_name where created_on &lt; today;</code></p>
<p>In that case we would prefer to have a view with this query and call that view.</p>
<p>In all the above situations, it is pretty easy to use our database views with Rails.</p>
<p>How?</p>
<p>Simply create your model as you would for a table and it will work fine just like your model for a database table.</p>
<p><strong>Interesting thing is, apart from viewing data using views I can even update, delete and insert data in my database tables using my views with all those ActiveRecord/ORM niceties (in Sybase) as long as each database view consists of only one table</strong>. If you are using more than one table in your database views then you can only view data but cannot do delete, update and insert operation.</p>
<p>I think this is really useful if we have a database that do not conform to Rails conventions but we would like to follow those conventions without changing the current database if other applications depend on it as well.  Simply create views for each table in the database and use those views for our models instead of actual tables.</p>
<p>Those single table views (in other words updatable views) will allow us to follow Rails database conventions without changing our existing database tables while also keeping our database guys happy ;o)</p>
<p>(<a href="http://nasir.wordpress.com/2007/10/24/not-following-rails-table-and-field-conventions/">Though we also have other options if we are not following rails conventions</a>)</p>
<p><strong>NOTE: I have tried updatable views only with Sybase and would love to know about your experience with other databases.</strong></p>
<hr size="1" /><strong>Sign up and be a part of <a href="http://www.sphred.com" title="Spread It | Shred It" target="_blank">SPhred.com</a> and don&#8217;t forget to invite your friends ;o)</strong><em> </em><br />
<hr size="1" />
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nasir.wordpress.com/41/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nasir.wordpress.com/41/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nasir.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nasir.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nasir.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nasir.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nasir.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nasir.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nasir.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nasir.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nasir.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nasir.wordpress.com/41/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=41&subd=nasir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://nasir.wordpress.com/2007/12/17/database-views-and-rails/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/170b5dc385cc9ddf78ed01bcf1e6990a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nasir</media:title>
		</media:content>
	</item>
		<item>
		<title>Stored Procedures and Rails &#8211; Part 2</title>
		<link>http://nasir.wordpress.com/2007/12/04/stored-procedures-and-rails-part-2/</link>
		<comments>http://nasir.wordpress.com/2007/12/04/stored-procedures-and-rails-part-2/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 04:53:25 +0000</pubDate>
		<dc:creator>nasir</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[stored procedures]]></category>

		<guid isPermaLink="false">http://nasir.wordpress.com/2007/12/04/stored-procedures-and-rails-part-2/</guid>
		<description><![CDATA[
Continued from Stored Procedures and Rails &#8211; Part 1
Now we know how to call our good and reliable stored procedures but there is a difference when we get records from database using Rails ORM/ActiveRecord compared to a stored procedure. This requires a different approach to access records returned from a stored procedure.
Lets say we have [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=40&subd=nasir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fprogramming%2FStored_Procedures_and_Rails_Part_2' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe><br />
<a href="http://nasir.wordpress.com/2007/12/03/stored-procedures-and-rails/">Continued from Stored Procedures and Rails &#8211; Part 1</a></p>
<p>Now we know how to call our good and reliable stored procedures but there is a difference when we get records from database using Rails ORM/ActiveRecord compared to a stored procedure. This requires a different approach to access records returned from a stored procedure.</p>
<p>Lets say we have a table orders and a corresponding model Order. We all know, how to access data using ActiveRecord, eg.</p>
<pre>
@orders = Order.find(:all, :conditions =&gt; ["some simple condition"])</pre>
<p>then what is returned to us is an array of order objects which we can access by either using a block or a for loop. For instance,</p>
<pre>
for order in @orders
  puts order.order_name
end</pre>
<p>but this is not possible in case if we use a stored procedure to get data on orders because we don&#8217;t get back an array of order objects instead we simply get back an array of hashes, ie. an array of records with their attributes and values. Hence, the above code will not work.<br />
Lets say you call your stored procedure, like this</p>
<pre>
@orders = CallStoredProcedure.fetch_records("exec procedure_name 'args1', 'args2'")</pre>
<p>as mentioned in the <a href="http://nasir.wordpress.com/2007/12/03/stored-procedures-and-rails/">previous post</a>.<br />
Then you need to access records with a little modification within your for loop</p>
<pre>
for order in @orders
  puts order['order_name']
end</pre>
<p>I thought this might save sometime who are new to using stored procedures.</p>
<p>NOTE: The only downside of using stored procedures in Rails currently is; you cannot use the Object Relational Mapping which you might have been used to by know, ie. picking all children of an order by simply typing</p>
<pre>
order.children</pre>
<p>The best thing to do is to use stored procedures judiciously and mainly for complex logic/calculation in your database but when you want to do something simple with your data like simply showing something or a quick update then use ORM over stored procedures.</p>
<hr size="1" /><strong>Sign up and be a part of <a href="http://www.sphred.com" title="Spread It | Shred It" target="_blank">SPhred.com</a> and don&#8217;t forget to invite your friends ;o)</strong><em> </em></p>
<hr size="1" />
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nasir.wordpress.com/40/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nasir.wordpress.com/40/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nasir.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nasir.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nasir.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nasir.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nasir.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nasir.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nasir.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nasir.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nasir.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nasir.wordpress.com/40/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=40&subd=nasir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://nasir.wordpress.com/2007/12/04/stored-procedures-and-rails-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/170b5dc385cc9ddf78ed01bcf1e6990a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nasir</media:title>
		</media:content>
	</item>
		<item>
		<title>Stored Procedures and Rails &#8211; Part 1</title>
		<link>http://nasir.wordpress.com/2007/12/03/stored-procedures-and-rails/</link>
		<comments>http://nasir.wordpress.com/2007/12/03/stored-procedures-and-rails/#comments</comments>
		<pubDate>Mon, 03 Dec 2007 20:23:06 +0000</pubDate>
		<dc:creator>nasir</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[stored procedures]]></category>

		<guid isPermaLink="false">http://nasir.wordpress.com/2007/12/03/stored-procedures-and-rails/</guid>
		<description><![CDATA[
There is no documentation in Rails about how to use stored procedures or atleast it is difficult to find where to look at. And according to DHH stored procedures is not the Rails Way to do things. DHH mentioned in his post
I want a single layer of cleverness: My domain model. Object-orientation is all about [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=39&subd=nasir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fprogramming%2FUsing_stored_procedures_in_rails' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe><br />
There is no documentation in Rails about how to use stored procedures or atleast it is difficult to find where to look at. And according to <a href="http://web.archive.org/web/20060418215514/http://www.loudthinking.com/arc/000516.html" target="_blank">DHH</a> stored procedures is not the <strong>Rails Way</strong> to do things. DHH mentioned in his post</p>
<blockquote><p>I want a single layer of cleverness: My domain model. Object-orientation is all about encapsulating clever. Letting it sieve half ways through to the database is a terrible violation of those fine intentions. And I want no part of it.</p></blockquote>
<p>I somewhat agree to what DHH has to say. And that&#8217;s all fine but what if we don&#8217;t have any other option apart from using stored procedure and our stored procedure has some complex logic which we don&#8217;t want to put in our Ruby code then here is a little hack to it</p>
<pre>
ActiveRecord::Base.connection.execute("execute procedure_name")</pre>
<p>But the above line will not return anything it will only execute your procedure, considering everything went OK.</p>
<p>Moreover, it&#8217;s not DRY if everytime you have to write that line of code just to call a procedure.</p>
<p>Here is a better way to do it:</p>
<p>1) Create a class and let&#8217;s call it</p>
<pre>
Class CallStoredProcedures
  your methods here .......
end</pre>
<p>2) Create a class method within it</p>
<pre>
def self.fetch_db_records(proc_name_with_parameters)
  ActiveRecord::Base.connection.execute(proc_name_with_parameters)
end</pre>
<p>Then simply call it as</p>
<pre>
CallStoredProcedures.fetch_db_records("exec procedure_name 'args1', 'args2', 'and so on' ")</pre>
<p>Now you might say, that this will only execute a procedure (as I mentioned above) what if I want to return records or values from stored procedures. Then I will prefer class methods and this is how I would do it,</p>
<pre>
class CallStoredProcedures &lt; ActiveRecord::Base

  def self.fetch_db_records(proc_name_with_parameters)
    connection.select_all(proc_name_with_parameters)
  end

  def self.insert_update_delete_calculate(proc_name_with_parameters)
    connection.execute(proc_name_with_parameters)
  end

  def self.fetch_val_from_sp(proc_name_with_parameters)
    connection.select_value(proc_name_with_parameters)
  end

end</pre>
<p>And then simply call it like</p>
<pre>
CallStoredProcedures.method_name("exec procedure_name 'args1', 'args2', 'and so on' ")</pre>
<p>Sweet&#8230;</p>
<p>If you know a better way to do it then I would love to know your views.</p>
<p><a href="http://nasir.wordpress.com/2007/12/04/stored-procedures-and-rails-part-2/">Stored Procedures and Rails &#8211; Part 2 </a></p>
<hr size="1" /><strong>Sign up and be a part of <a href="http://www.sphred.com" title="Spread It | Shred It" target="_blank">SPhred.com</a> and don&#8217;t forget to invite your friends ;o)</strong><em> </em><br />
<hr size="1" />
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nasir.wordpress.com/39/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nasir.wordpress.com/39/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nasir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nasir.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nasir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nasir.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nasir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nasir.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nasir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nasir.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nasir.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nasir.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=39&subd=nasir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://nasir.wordpress.com/2007/12/03/stored-procedures-and-rails/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/170b5dc385cc9ddf78ed01bcf1e6990a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nasir</media:title>
		</media:content>
	</item>
		<item>
		<title>RSS Feeds + Ruby on Rails + Web App</title>
		<link>http://nasir.wordpress.com/2007/12/03/rss-feeds-ruby-on-rails-web-app/</link>
		<comments>http://nasir.wordpress.com/2007/12/03/rss-feeds-ruby-on-rails-web-app/#comments</comments>
		<pubDate>Mon, 03 Dec 2007 05:34:06 +0000</pubDate>
		<dc:creator>nasir</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[feeds]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[web app]]></category>

		<guid isPermaLink="false">http://nasir.wordpress.com/2007/12/03/rss-feeds-ruby-on-rails-web-app/</guid>
		<description><![CDATA[
The Feedtools library is a very comprehensive and powerful Ruby library for handling rss, atom, etc as well as caching. It makes creating, consuming and manipulating feeds a piece of cake.
It’s ideal for parsing RSS feeds in Ruby on Rails applications.
Assuming that you already have installed Ruby and Rubygem, simply run
gem install feedtools
to install the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=38&subd=nasir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fprogramming%2FHow_to_show_RSS_feeds_in_a_Ruby_on_Rails_Apps' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe><br />
The <a href="http://sporkmonger.com/projects/feedtools/" target="_blank">Feedtools</a> library is a very comprehensive and powerful Ruby library for handling rss, atom, etc as well as caching. It makes creating, consuming and manipulating feeds a piece of cake.</p>
<p>It’s ideal for parsing RSS feeds in Ruby on Rails applications.</p>
<p>Assuming that you already have installed Ruby and Rubygem, simply run</p>
<pre>gem install feedtools</pre>
<p>to install the FeedTools gem</p>
<p>or download it from the <a href="http://rubyforge.org/frs/?group_id=775" target="_blank">FeedTools project page</a> and put the untar/unzipped folder in the vendor/plugins directory of your app.</p>
<p>To do a very quick test, create a file called testfeed.rb and add the below code in it:</p>
<pre>
    require "RubyGems"
    require "feed_tools"

    feedurls = 'http://www.sphred.com/combined_feed'
    # If you want to fetch more than one feed then comment the above feedurls variable and   uncomment the below one.
    #feedurls = %w(http://feeds.feedburner.com/Sphred_top_10_feeds   http://feeds.feedburner.com/Sphred_site_only http://feeds.feedburner.com/Sphred_site_feature)
    my_feeds = FeedTools::build_merged_feed feedurls

    my_feeds.title = 'Sphred.com Feed'
    my_feeds.copyright = 'SPhred'
    my_feeds.author = 'Nasir '
    my_feeds.id = "http://www.sphred.com/combined_feed"

    File.open('./my_feeds.xml', 'w') do |file|
      file.puts my_feeds.build_xml()
    end

    puts "Checkout Sphred.com while I fetct feeds for you"</pre>
<p>Running this file from IRB will create a my_feeds.xml file in your current directory with all the feed contents.</p>
<p>To show feeds on a website, you need to do a few things:<br />
1) Put</p>
<pre>require "feed_tools"</pre>
<p>at the top of your controller<br />
2) Create an action within this controller to show your feeds, lets call that action user_data</p>
<pre>
    def user_data
      @feed = FeedTools::Feed.open(params[:feed_url])
      # You can first test it with a static feed url like this
      #@feed = FeedTools::Feed.open('http://www.sphred.com/combined_feed')
    end</pre>
<p>3) In the corresponding view add this code</p>
<pre>
  &lt;div class="feeds"&gt;
    &lt;h3&gt;
      &lt;a href="&lt;%= h @feed.link %&gt;"&gt;
      &lt;%= @feed.title %&gt;&lt;/a&gt;
    &lt;/h3&gt;
    &lt;p&gt;&lt;%= @feed.description %&gt;&lt;/p&gt;
    &lt;% for feed in @feed.items %&gt;
      &lt;div class="feed_item"&gt;
        &lt;h4&gt;
          &lt;a href="&lt;%= h feed.link %&gt;"&gt;
          &lt;%= feed.title %&gt;&lt;/a&gt;
        &lt;/h4&gt;
        &lt;p&gt;&lt;%= feed.description %&gt;&lt;/p&gt;
     &lt;/div&gt;
   &lt;% end %&gt;
 &lt;/div&gt;</pre>
<p>This is all good for development environment or for small apps but once you go to production environment then you have to think of caching to avoid hitting the feed server every time before displaying feed contents.</p>
<hr size="1" /><strong>Sign up and be a part of <a href="http://www.sphred.com" title="Spread It | Shred It" target="_blank">SPhred.com</a> and don&#8217;t forget to invite your friends ;o)</strong><em> </em></p>
<hr size="1" />
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nasir.wordpress.com/38/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nasir.wordpress.com/38/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nasir.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nasir.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nasir.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nasir.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nasir.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nasir.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nasir.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nasir.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nasir.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nasir.wordpress.com/38/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=38&subd=nasir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://nasir.wordpress.com/2007/12/03/rss-feeds-ruby-on-rails-web-app/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/170b5dc385cc9ddf78ed01bcf1e6990a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nasir</media:title>
		</media:content>
	</item>
		<item>
		<title>Extreme Programming &#8211; xp</title>
		<link>http://nasir.wordpress.com/2007/11/16/extreme-programming-xp/</link>
		<comments>http://nasir.wordpress.com/2007/11/16/extreme-programming-xp/#comments</comments>
		<pubDate>Fri, 16 Nov 2007 06:19:26 +0000</pubDate>
		<dc:creator>nasir</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[extreme programming]]></category>
		<category><![CDATA[xp]]></category>

		<guid isPermaLink="false">http://nasir.wordpress.com/2007/11/16/extreme-programming-xp/</guid>
		<description><![CDATA[I prepared a mind map based on Kent Beck&#8217;s book. Extreme Programming &#8211; mind map.
I will be updating this post with a new mind map and some write  up in the next few days, so check back soon.
Sign up and be a part of SPhred.com and don&#8217;t forget to invite your friends ;o) 

 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=36&subd=nasir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I prepared a mind map based on Kent Beck&#8217;s book. <a href="http://nasir.files.wordpress.com/2007/11/xp.png" title="Extreme Programming - click here to view mind map">Extreme Programming &#8211; mind map.</a></p>
<p>I will be updating this post with a new mind map and some write  up in the next few days, so check back soon.</p>
<hr size="1" /><strong>Sign up and be a part of <a href="http://www.sphred.com" title="Spread It | Shred It" target="_blank">SPhred.com</a> and don&#8217;t forget to invite your friends ;o)</strong><em> </em><br />
<hr size="1" />
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nasir.wordpress.com/36/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nasir.wordpress.com/36/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nasir.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nasir.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nasir.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nasir.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nasir.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nasir.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nasir.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nasir.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nasir.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nasir.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=36&subd=nasir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://nasir.wordpress.com/2007/11/16/extreme-programming-xp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/170b5dc385cc9ddf78ed01bcf1e6990a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nasir</media:title>
		</media:content>
	</item>
		<item>
		<title>New features on SPhred.com</title>
		<link>http://nasir.wordpress.com/2007/11/05/new-features-on-sphred/</link>
		<comments>http://nasir.wordpress.com/2007/11/05/new-features-on-sphred/#comments</comments>
		<pubDate>Mon, 05 Nov 2007 02:38:39 +0000</pubDate>
		<dc:creator>nasir</dc:creator>
				<category><![CDATA[SP|hred.com]]></category>
		<category><![CDATA[add photo]]></category>
		<category><![CDATA[new features]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[sphred]]></category>

		<guid isPermaLink="false">http://nasir.wordpress.com/2007/11/05/new-features-on-sphred/</guid>
		<description><![CDATA[
First, A big thanks to all the guys out there for registering and sending invitation to their friends/relatives to try out sphred.com
SPhred is currently in very early stages, like what other sites say &#8216;in beta&#8217;.
A few things are added on SPhred in the last couple of days:
1) Earlier you first had to create a post [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=34&subd=nasir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Ftech_news%2FSphred_com_has_launched_some_new_features%2Fblog' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe></p>
<p>First, A big thanks to all the guys out there for registering and sending invitation to their friends/relatives to try out <a href="http://www.sphred.com">sphred.com</a></p>
<p>SPhred is currently in very early stages, like what other sites say &#8216;in beta&#8217;.</p>
<p>A few things are added on SPhred in the last couple of days:</p>
<p>1) Earlier you first had to create a post and then could add tags to it but now you can add tags while creating a post.</p>
<p>2) Now you can put a face to your name i.e. add a picture. This functionality is available by going to your profile page. The option is given just below &#8220;Profile for your name&#8221;. You can access your profile page after signing in by clicking on your email address part of &#8216;Signed in as your <strong>email address</strong>&#8216;.</p>
<p>3) Page to view users who sphredded an item has been redone and looks much better now (atleast I think so). Have a look by clicking on the number of users who sphreaded an item. Or you can directly go here <a href="http://sphred.com/users_sphredding/9-tutsbuzzcom">http://sphred.com/users_sphredding/9-tutsbuzzcom</a></p>
<p>4) Search is functional now though currently it only looks for the search term in a Sphred Item&#8217;s title or description.</p>
<p>6) Comments look much better now as you can see the picture of people who posted comments.</p>
<p>I would love to hear your feedback or suggestions i.e. what you would like to have on sphred and what you think isn&#8217;t working or won&#8217;t work.</p>
<p>Once again thank you all for using sphred.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nasir.wordpress.com/34/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nasir.wordpress.com/34/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nasir.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nasir.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nasir.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nasir.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nasir.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nasir.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nasir.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nasir.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nasir.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nasir.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=34&subd=nasir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://nasir.wordpress.com/2007/11/05/new-features-on-sphred/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/170b5dc385cc9ddf78ed01bcf1e6990a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nasir</media:title>
		</media:content>
	</item>
		<item>
		<title>Not binding your selection list to a particular model in Rails</title>
		<link>http://nasir.wordpress.com/2007/11/02/not-binding-your-selection-list-to-a-particular-model-in-rails/</link>
		<comments>http://nasir.wordpress.com/2007/11/02/not-binding-your-selection-list-to-a-particular-model-in-rails/#comments</comments>
		<pubDate>Fri, 02 Nov 2007 09:23:09 +0000</pubDate>
		<dc:creator>nasir</dc:creator>
				<category><![CDATA[Ruby On Rails]]></category>
		<category><![CDATA[collection_select]]></category>
		<category><![CDATA[drop down box]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[selection list]]></category>
		<category><![CDATA[select_tag]]></category>

		<guid isPermaLink="false">http://nasir.wordpress.com/2007/11/02/not-binding-your-selection-list-to-a-particular-model-in-rails/</guid>
		<description><![CDATA[
In Rails, we use collection_select helper to display values from a particular model using a drop down  but it is generally tied to a particular model, i.e. if we look at the generated html then we see something like

select name="customer[customer_search]" id="customer_customer_search"

What if we want something like:

select name="customer_search" id="customer_search"

Then we can simply use select_tag helper [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=33&subd=nasir&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><iframe src='http://digg.com/api/diggthis.php?u=http%3A%2F%2Fdigg.com%2Fprogramming%2FNot_binding_your_selection_list_to_a_particular_model_in_Rails' height='82' width='55' frameborder='0' scrolling='no' style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'></iframe><br />
In Rails, we use collection_select helper to display values from a particular model using a drop down  but it is generally tied to a particular model, i.e. if we look at the generated html then we see something like<br />
<code><br />
select name="customer[customer_search]" id="customer_customer_search"<br />
</code><br />
What if we want something like:<br />
<code><br />
select name="customer_search" id="customer_search"<br />
</code><br />
Then we can simply use select_tag helper and get the values from our model like this<br />
<code><br />
customers = Customer.find(:all, <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> rder =&gt; 'first_name').map{|x| [x.full_name] + [x.id]}<br />
select_tag(:customer_search, options_for_select(customers))<br />
</code><br />
If we don&#8217;t want to display the values from model and would like to feed in something simple and manually, then<br />
<code><br />
customers = [['text_to_display1', 'value1'], ['text_to_display2', 'value2']]<br />
select_tag(:customer_search, options_for_select(customers))<br />
</code><br />
If text_to_display and its value both are same then we can use something as simple as:<br />
<code><br />
customers = ['wee', 'asdf']<br />
select_tag(:customer_search, options_for_select(customers))<br />
</code></p>
<hr size="1" /><strong>Sign up and be a part of <a href="http://www.sphred.com" title="Spread It | Shred It" target="_blank">SPhred.com</a> and don&#8217;t forget to invite your friends ;o)</strong><em> </em></p>
<hr size="1" />
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/nasir.wordpress.com/33/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/nasir.wordpress.com/33/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nasir.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nasir.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nasir.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nasir.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nasir.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nasir.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nasir.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nasir.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nasir.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nasir.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nasir.wordpress.com&blog=50482&post=33&subd=nasir&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://nasir.wordpress.com/2007/11/02/not-binding-your-selection-list-to-a-particular-model-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/170b5dc385cc9ddf78ed01bcf1e6990a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">nasir</media:title>
		</media:content>
	</item>
	</channel>
</rss>