<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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" version="2.0">

<channel>
	<title>Nazgum's Blog</title>
	
	<link>http://www.nazgum.com</link>
	<description>The dirty potato gets eaten last..</description>
	<pubDate>Tue, 28 Oct 2008 15:14:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/nazgum" type="application/rss+xml" /><item>
		<title>Making Open RVR Awesome in Warhammer</title>
		<link>http://www.nazgum.com/2008/10/28/making-open-rvr-awesome-in-warhammer/</link>
		<comments>http://www.nazgum.com/2008/10/28/making-open-rvr-awesome-in-warhammer/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 15:14:10 +0000</pubDate>
		<dc:creator>Nazgum</dc:creator>
		
		<category><![CDATA[Warhammer]]></category>

		<guid isPermaLink="false">http://www.nazgum.com/?p=326</guid>
		<description><![CDATA[Open RVR is not nearly as fun or active as it should be in Warhammer; there are many possible reasons for this, but perhaps the biggest is it is just not rewarding enough.  Fortunately, this is something Mythic can fix.  So what can be done to make Open RVR more rewarding?
Keeps should be Contested Public [...]]]></description>
			<content:encoded><![CDATA[<p>Open RVR is not nearly as fun or active as it should be in Warhammer; there are many possible reasons for this, but perhaps the biggest is it is just not rewarding enough.  Fortunately, this is something Mythic can fix.  So what can be done to make Open RVR more rewarding?</p>
<p><strong>Keeps should be Contested Public Quests that can reward Defenders. </strong> A keep should be a multistage contested pq, where the first stage is breaching the outer wall, the second stage is breaching the inner wall, and the final stage is killing the keep lord.  Defenders should be rewarded with the completion of the pq if they repel the attackers at any stage; each stage should be timed, say 20 minutes or so.  And a kill counter should be active for the keep, to make it more fun, showing the kills on each side while it is under siege.  Even if the attackers fail, at the end of that contested pq they should receive some small reward; this would encourage the idea that attacking or defending keeps is always rewarding.</p>
<p><strong>Taking Keeps should be more rewarding when defended.</strong> Taking a keep grants XP, renown and loot.  Taking a keep that is not defended at all should reward much less XP, renown and loot then a heavily defended keep that took effort to take.  For example, a defended keep where 30 attackers had to break through a warband of defenders to take the keep should get 50k XP, 5k renown and some purple bags.  Whereas 30 attackers who stole an undefended keep at 5am should get 1k XP, 100 renown and green bags.</p>
<p><strong>Holding a Keep needs to be more rewarding. </strong> Holding a keep currently grants no meaningful bonus.  No one cares if they own keeps.  A meaningful solution to this has already been found in DAOC; darkness falls.  And its simple to add in Warhammer.  In tier 3, make Gunbad only open to the realm that currently holds the majority of the keeps; and increase the loot rewards from Gunbad to make it the best gear option in Tier 3.  Bastion Stairs can help entice Tier 4 by functioning the same way (though tier 4 needs less incentive due to city sieges); and then add a similar dungeon in Tier 2 and do the same thing.  This way owning keeps in each tier provides an actual reason to want to hold them - you gain access to a dungeon with sweet loot you cannot get any other way.</p>
<p><strong>Remove renown gain from scenarios.</strong> I personally believe scenarios are the worst mistake Mythic has made with Warhammer; introducing them has had an attrocious effect on the game, making the game world barren and empty, both in the RVR lakes and at Public Quests.  But since scenarios likely won&#8217;t be going anywhere, the next best thing Mythic can do is remove renown gains from them.  This allows people who want to use them as an option to level continue to do so, and people who enjoy them can continue doing them, but it prevents people from grinding them to max realm rank, and gives further meaning to the RVR lakes by making those the place you gain renown.  Making the renown gear a little more worthwhile would perhaps get more into the RVR lakes while leveling also.</p>
<p><strong>RVR Lakes should have influence rewards.</strong> Each RVR lake in each pairing should have an influence bar and have unique influence rewards.  Would be nice if it formed a set so players want to fight in all 3 of the lakes in each tier to get that set of gear.  The influence for these should not be rewarded from scenarios or taking battlefield objectives or keeps; it should be rewarded purely from killing other players in the RVR lakes (killing players at keeps or BOs would still count); as a way to encourage skirmish fighting in the game.</p>
<p><strong>Zone Control needs to be reworked. </strong> The idea of &#8220;everything you do contributes to the war effort&#8221; sounded real nice and markety leading up to the game; but the truth is its too complex and it just doesn&#8217;t work.  Owning all of the objectives and then having to go grind a public quest to get enough points to take the zone is extremely lame.  Holding all the objectives in a zone needs to be all that is required to capture the zone; once you hold all objectives, the opposing realm should have 10 minutes or so to reclaim something or the zone is yours.</p>
<p><strong>Diminishing returns in Open RVR need to go.</strong> Improving experience gains by 100% in Open RVR while diminishing returns are still in place really doesn&#8217;t do much.  Very quickly players become almost worthless to kill.  It&#8217;s very discouraging to finally get a few kills after hunting around the RVR lakes for 30 minutes only to see those players were killed recently and grant you almost nothing.  Remove diminishing returns, or at least greatly reduce them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nazgum.com/2008/10/28/making-open-rvr-awesome-in-warhammer/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Warhammer Online: My Biggest Complaints</title>
		<link>http://www.nazgum.com/2008/09/30/warhammer-online-my-biggest-complaints/</link>
		<comments>http://www.nazgum.com/2008/09/30/warhammer-online-my-biggest-complaints/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 11:39:51 +0000</pubDate>
		<dc:creator>Nazgum</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.nazgum.com/?p=322</guid>
		<description><![CDATA[With a title like that I need to preface this post right away: I am thoroughly enjoying Warhammer Online.  I&#8217;ve been looking forward to it since it was first announced, and I&#8217;ve been playing it almost every spare moment I&#8217;ve had since launch.  That being said there is quite a few issues with the game [...]]]></description>
			<content:encoded><![CDATA[<p>With a title like that I need to preface this post right away:<strong> </strong><em>I am thoroughly enjoying Warhammer Online.</em>  I&#8217;ve been looking forward to it since it was first announced, and I&#8217;ve been playing it almost every spare moment I&#8217;ve had since launch.  That being said there is quite a few issues with the game that need to be addressed, and as Mythic has said it is looking for user feedback I figure I&#8217;ll take a moment to post some of my biggest complaints with the current game.</p>
<p><strong>Scenario Queue Times:</strong> While scenarios are more fun then I expected them to be, the queues can take far too long to pop, especially if you are playing early in the morning or really late at night.  And this is in an optimal setting where everyone is mostly in the same tiers and our server has a high population.  Once most people are 40 and there is fewer players in tiers 1-3 the queues will be painfully slow.  <em>Solution: Implement cross-server queues and the total earned from the players on your realm is contributed to your server.</em></p>
<p><strong>Scenario Repeatable Quests: </strong>For each tier, there are 2 repeatable quests for the scenarios.  One for completing them, and one for killing players inside of them.  Together they amount to about 3000xp, which is about 1/3 what you get for winning the average scenario, or about the full amount if you lose.  Because these quests are worth so much, if you are trying to level through pvp you don&#8217;t want to leave this mob.  This turns what should have been a boon of the scenarios, that you can do your own thing while queue&#8217;d and just hop in them when they pop, into a negative; in reality you can&#8217;t do that, or don&#8217;t want to, because if the scenarios are popping relatively quick its difficult to earn more than that 3k xp, so its safer to stay at the mob.  This turns the game into a real drag, as you just sit there staring at the screen waiting for the scenario to pop.  <em>Solution: either get rid of these quests or make them auto-complete after the scenario so you can do your own thing.</em></p>
<p><strong>Lack of Skirmish Open RVR:</strong> By far my favorite type of PVP is skirmish open rvr.  Running into another small group with your small group always amounts to exciting, fun fights.  But skirmish pvp is far too rare in WAR.  People are either doing scenarios, or they are hitting a keep with their guild.  I think the problem is there is nothing to do in the rvr lakes except take a keep or BO, which requires a good sized group; so the solo players and small groups that enter those areas, do a lap, see no one and leave.  Which leaves the rvr lakes empty, except when a guild decides to go for a keep, which then results in a zerg.  <em>Solution: Provide more things to do in the rvr lakes for single players or small groups, throw in more quests, mobs to kill, put some public quests there!  Give players something to do so they aren&#8217;t forced to stand around doing nothing hoping someone shows up to fight.</em></p>
<p><strong>Collision Detection is Garbage:</strong> Collision detection was a nice idea, but from everything I&#8217;ve seen it&#8217;s worthless in WAR.  Versus enemies your collision detection area seems quite small and it&#8217;s difficult to block anyone, but due to server latency and coding, which makes players appear to be in a location they are not, you try to block a witch hunter from running past you as your black orc and it shows you block them on your screen, only to have the client refresh a second later and see you never blocked them at all, they went right by you and are on your healer.  Conversely, attempting to run through your allies with the ball in Morkain&#8217;s is an excersise in frustration as everyone seems to block you far too easily.  <em>Solution: larger collision area with more correct positioning for enemies, and smaller collision detection for allies.</em></p>
<p><strong>Client Bugs: </strong> I know this will be fixed, but honestly the client bugs are horribly annoying and the issue needs to have as much attention as possible.  I&#8217;ve died too many times as my shaman hammering F9 for my rank 1 morale heal, only to have it completely bug out and refuse to fire.  Plans reset as my black orc.  Abilities fail for no apparent reason.  Animations go out of sync.  Framerate is horrible even on fast machines.  There appears to be a memory leak..  the client is just one massive bugfest at the moment and needs some serious work.  <em>Solution: make Gork fix it!</em></p>
<p><strong>I am missing my immersion:</strong> I was discussing this with <a title="Snafzg's pvp kungfu is weaksauce!" href="http://thegreenskin.com" target="_blank">Snafzg</a>, and he suggests this may be by design, but WAR makes me far too aware I am playing a game.  That may sound like a good thing, but for an MMORPG I would say it&#8217;s not.  The whole purpose of an MMORPG is to make an online virtual world, where you play a character and can get immersed in it.  With WAR, I really lack the sense I&#8217;m playing a character in a virtual world.  With WoW, there was always the sense I was in a virtual world from the moment you logged in, because it was one seamless world and you were always aware of where your character was in it.  In WAR, I am literally porting all over every few moments, whether to another tier&#8217;s warcamp, or to IC, or into some scenario, my character&#8217;s feet doesn&#8217;t stay on the ground in one area for more then a few moments before he&#8217;s wisked off somewhere else.  WAR wanted to eliminate most &#8220;forced downtime&#8221;, but perhaps something else gets lost with it.  A great feeling the first time in WoW was walking up the road from your starting area and seeing Orgrimmar rise in the distance, or making the trek from Thunder Bluff to there; you got a great sense of adventure and exploration in that game.  Perhaps some downtime is a necessary evil.  In Warhammer, I don&#8217;t even know how to walk to IC, or most other places, I just port there and the excitement is lost.  I&#8217;m not in a virtual world, I&#8217;m in a series of connected portals, and I&#8217;m far too aware of that fact.  <em>Solution: I don&#8217;t see one in the near future, let&#8217;s hope the PVP and other features makes up for it.</em></p>
<p><strong>I miss a third realm:</strong> A huge uprising of people said it was a mistake when Mythic announced there would only be two sides, and only one week into release I really think they were right.  I already really miss having a third realm to add excitement to the game.  With two sides, it&#8217;s just so absolute.  Your team is either winning or losing, there is no third realm to be the monkey wrench and show up and ruin your plans.  My two favorite games were MUME and DaoC, and both had 3 sides.  WAR only has 2, and even in the lower tiers I feel the lack of excitement a third side could bring weighing down on my enjoyment of the game.  At endgame, it seems like it will be much worse.  Population imbalances are such an important issue, and with three realms it is so much easier, since the two lower pops can always gang up on the higher pop.  A three way fight will always be more interesting then a two way one.  <em>Solution: we know you won&#8217;t, but it would be awesome if an expansion introduced a third realm, purposefully set at a slight disadvantage, for hardcore players to have a challenge and can add back the three-way excitement to the game *hint skaven!*</em></p>
<p>Those would be my main issues.  Again as I said, I am loving the game.  I just hope to see it get even better, and voicing the main detrements to my enjoyment hopefully helps make that happen =)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nazgum.com/2008/09/30/warhammer-online-my-biggest-complaints/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Prototype.js Classes with Rails to_json</title>
		<link>http://www.nazgum.com/2008/09/04/using-prototypejs-classes-with-rails-to_json/</link>
		<comments>http://www.nazgum.com/2008/09/04/using-prototypejs-classes-with-rails-to_json/#comments</comments>
		<pubDate>Thu, 04 Sep 2008 12:29:49 +0000</pubDate>
		<dc:creator>Nazgum</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.nazgum.com/?p=320</guid>
		<description><![CDATA[Ruby on Rails comes bundled with prototype.js and can be setup to populate some prototype classes for you very easily.  I&#8217;ve had to play around with it lately so I thought I would do a quick post on it.
First, lets say we have a simple &#8220;book&#8221; model to work with:

1
2
3
4
5
6
7
8
ruby script/generate model book category_id:integer [...]]]></description>
			<content:encoded><![CDATA[<p>Ruby on Rails comes bundled with prototype.js and can be setup to populate some prototype classes for you very easily.  I&#8217;ve had to play around with it lately so I thought I would do a quick post on it.</p>
<p>First, lets say we have a simple &#8220;book&#8221; model to work with:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="ruby">ruby script<span style="color:#006600; font-weight:bold;">/</span>generate model book category_id:<span style="color:#CC0066; font-weight:bold;">integer</span> title:<span style="color:#CC0066; font-weight:bold;">string</span> author:<span style="color:#CC0066; font-weight:bold;">string</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># our migration with fields would look like this then</span>
create_table <span style="color:#996600;">&quot;books&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
  t.<span style="color:#CC0066; font-weight:bold;">integer</span> <span style="color:#996600;">&quot;category_id&quot;</span>
  t.<span style="color:#CC0066; font-weight:bold;">string</span> <span style="color:#996600;">&quot;title&quot;</span>
  t.<span style="color:#CC0066; font-weight:bold;">string</span> <span style="color:#996600;">&quot;author&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>So now lets create a class in javascript for these books:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="javascript">Book = <span style="color: #003366; font-weight: bold;">Class</span>.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>
  initialize: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>params<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">id</span> = params.<span style="color: #006600;">id</span>;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">category_id</span> = params.<span style="color: #006600;">category_id</span>;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">title</span> = params.<span style="color: #006600;">title</span>;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">author</span> = params.<span style="color: #006600;">author</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>Now we can do this to create books:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript">  <span style="color: #003366; font-weight: bold;">var</span> archie = <span style="color: #003366; font-weight: bold;">new</span> Book<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span> id: <span style="color: #CC0000;">1</span>, category_id: <span style="color: #CC0000;">2</span>, title: <span style="color: #3366CC;">&quot;Archie Digest&quot;</span>, author: <span style="color: #3366CC;">&quot;Vic Bloom&quot;</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #003366; font-weight: bold;">var</span> jughead = <span style="color: #003366; font-weight: bold;">new</span> Book<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span> id: <span style="color: #CC0000;">2</span>, category_id: <span style="color: #CC0000;">2</span>, title: <span style="color: #3366CC;">&quot;Jughead Double Digest&quot;</span>, author: <span style="color: #3366CC;">&quot;Vic Bloom&quot;</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>which works well, but we want to populate these directly from rails, to do this we would first in our rails controller grab the books:</p>
<p>app/controller/books.rb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> BooksController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  <span style="color:#9966CC; font-weight:bold;">def</span> index
    <span style="color:#0066ff; font-weight:bold;">@books</span> = Book.<span style="color:#9900CC;">all</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>And then in our view we can just do:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="javascript">Book = <span style="color: #003366; font-weight: bold;">Class</span>.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>
  initialize: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>params<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">id</span> = params.<span style="color: #006600;">id</span>;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">category_id</span> = params.<span style="color: #006600;">category_id</span>;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">title</span> = params.<span style="color: #006600;">title</span>;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">author</span> = params.<span style="color: #006600;">author</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> books_list = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #66cc66;">&lt;%</span> <span style="color: #66cc66;">@</span>books.<span style="color: #006600;">each</span> <span style="color: #000066; font-weight: bold;">do</span> <span style="color: #66cc66;">|</span>book<span style="color: #66cc66;">|</span> <span style="color: #66cc66;">%&gt;</span>
  books_list.<span style="color: #006600;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> Book<span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&lt;%</span>= b.<span style="color: #006600;">to_json</span> -<span style="color: #66cc66;">%&gt;</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&lt;%</span> end <span style="color: #66cc66;">%&gt;</span></pre></td></tr></table></div>

<p>Except that doesn&#8217;t quite work, by default rails will include book as the root node for the json object; you could adjust the code to work with that but personally I prefer to disable it, which you can do in the initializer:</p>
<p>app/config/initializers/new_rails_defaults.rb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="ruby"><span style="color:#008000; font-style:italic;"># Include Active Record class name as root for JSON serialized output.</span>
<span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color:#9900CC;">include_root_in_json</span> = <span style="color:#0000FF; font-weight:bold;">false</span>  <span style="color:#008000; font-style:italic;"># set this to false</span></pre></td></tr></table></div>

<p>And now it will work =)  We can actually streamline this a little also, rather then specifying this for each attribute in the Book&#8217;s initialize function we can just extend the params onto it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="javascript">Book = <span style="color: #003366; font-weight: bold;">Class</span>.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span>
  initialize: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>params<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    Object.<span style="color: #006600;">extend</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>, params<span style="color: #66cc66;">&#41;</span>;  <span style="color: #009900; font-style: italic;">// read passed in attributes</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> books_list = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #66cc66;">&lt;%</span> <span style="color: #66cc66;">@</span>books.<span style="color: #006600;">each</span> <span style="color: #000066; font-weight: bold;">do</span> <span style="color: #66cc66;">|</span>book<span style="color: #66cc66;">|</span> <span style="color: #66cc66;">%&gt;</span>
  books_list.<span style="color: #006600;">push</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> Book<span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&lt;%</span>= b.<span style="color: #006600;">to_json</span> -<span style="color: #66cc66;">%&gt;</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&lt;%</span> end <span style="color: #66cc66;">%&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.nazgum.com/2008/09/04/using-prototypejs-classes-with-rails-to_json/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Warhammer Beta Review</title>
		<link>http://www.nazgum.com/2008/08/21/warhammer-beta-review/</link>
		<comments>http://www.nazgum.com/2008/08/21/warhammer-beta-review/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 19:31:59 +0000</pubDate>
		<dc:creator>Nazgum</dc:creator>
		
		<category><![CDATA[MMORPGs]]></category>

		<category><![CDATA[Warhammer]]></category>

		<guid isPermaLink="false">http://www.nazgum.com/?p=319</guid>
		<description><![CDATA[So the NDA finally dropped and articles are popping up all over with info from beta, so I might as well jump on board =)
I was rather lucky to get into beta quite early, around may 2007; and way back then it was still quite fun, especially the low level PVP zones, and that was [...]]]></description>
			<content:encoded><![CDATA[<p>So the NDA finally dropped and articles are popping up all over with info from beta, so I might as well jump on board =)</p>
<p>I was rather lucky to get into beta quite early, around may 2007; and way back then it was still quite fun, especially the low level PVP zones, and that was what made me think this game will be a huge success.  Since then, Warhammer has received an incredible amount of polish and new features.  Despite the recent cuts there is still a huge amount of content in the game, and it is very fun to play through.</p>
<p>Personally, I am not much of a PVE person, so I am mostly interested in the PVP aspect of WAR.  But, even though I normally detest leveling in PVE, in Warhammer I often found it quite fun.  The public quest system is genius and will definitely be copied in all future MMORPGs; having a quest activate for you just by joining the area, allowing you to participate with others and have a short storyline unfold in front of you is wicked.</p>
<p>My favorite Public Quest so far is in the Greenskin Tier 2 zones.  It starts off when you enter this dark cave that has all these spectyres in it.  The first stage of the quest requires you to kill 50 spectyres, which i began doing alone; once I had killed around 40 or so i noticed some were being killed not by me, and found another person in the cave who also started doing it; we teamed up and after the 50th spectyre died, we had to collect 20 items in the cave, to lure out the boss spectyre.  That part went quite quickly between the two of us.</p>
<p>Finishing stage 2 of the quest, the boss spectyre appeared, which was quite cool to fight and a little challenging with just the 2 of us; but partway through the first a third person showed up (did i mention public quests rock); we stomped the spectyre boss, and then a wall in the back cave fell away to reveal a tunnel; inside it were 7 dwarven barricades we had to get through (little sandbag walls with 4 dwarves each behind em), with a short 10 minute deadline to complete it; so we charged through the tunnel wiping out each of the barricades just before the time would expire.  The next stage of the public quest had us come out of the tunnel and into a large underground cavern with a tower inside it, and 3 dwarf heros below; we had to kill the 3 dwarf heros to gain access to the tower.  After we killed them the tower door opened up and inside was the dwarf lord, the final boss of the PQ, which we got to slay and finally get access to the treasure for the PQ.</p>
<p>The concept of moving through the real world, as a tiered quest that others can join along the way just makes the game very enjoyable to play, even for cynics to PVE like me =)</p>
<p>Of course, the main feature for Warhammer for a lot of people will be the PVP/RVR, and that is where the game really shines.  There is 3 main types of PVP available in Warhammer that i&#8217;ve found: Scenarios, Open RVR, and Keep battles.</p>
<p>Scenarios are instanced, limited fights; very similar in concept to World of Warcraft&#8217;s Battlegrounds.  Originally I was quite skeptical of scenarios, I do not like the idea of instanced PVP; but I found it to work quite well in Warhammer for a few situations.  One is that it is a great way to break up PVE leveling; you can queue for a scenario from anywhere, and when its ready you can hop into it, participate in some nice PVP fights, and then when you&#8217;re done it dumps you back to where you were, allowing you to continue leveling.  Another use of scenarios is to avoid the sometimes zergy standoffs that can occur, if world RVR is not as exciting as it should be at the moment, you can hop into a scenario for some different type of fighting; and unlike WoW which only offers 3 different battlegrounds, Warhammer will have 40 different ones at launch, and likely be adding more in the future.</p>
<p>Next up is Open World RVR, and this is really my favorite type of fighting.  It can be unfair sometimes, but the unpredictability of it and the on-edge nature of it makes it very fun to me.  Open RVR is excellent in Warhammer because the game is designed from the ground up to support it.  Along with 3 different fronts for you to explore for fighting, each front is broken up into zones and you can take control of, moving the fight forward as you gain ground on your enemy.  Each zone is also setup intelligently to support Open RVR, with several objectives you want to take in each zone, such as Keeps and Battlefield Objectives.</p>
<p>I&#8217;ve had some amazingly fun fights in beta in Open RVR, especially as there is quite a few knockback type skills and the terrain in WAR is really incredible to fight in; lots of rocks, cliffs, ledges, trees etc to try and use to your advantage; my favorite fight so far in Open RVR was in a Tier 4 Dark elf vs High elf zone called Dragonwake, which has these steep cliffs leading up to high ground where the keeps are, and large lakes of water down below them.  We were losing as destruction and about 5 of us were coming up a side of the cliff while another 10 order were coming down, and we would have got stomped but I managed to push 5 of them off the cliff with &#8220;Gedoff!&#8221;, an offensive shaman skill you can get that knocks enemies back; 5 went flying down into the water below and we were able to win our fight on the ledge, then swoop down and finish off the ones trying to swim out of the water.</p>
<p>And finally there is Keep RVR, which I unfortunately did not find as much fun in beta as I was hoping, but I really think Keep battles need guilds to be fun; attempting to take or defend a keep with no organization or communication is not much fun; and I think at release once some real guilds get in this type of fighting will be much more enjoyable; especially if your guild owns the keep, as protecting it means that much more to you then.  Still, Keep fighting is quite interesting, you have 4 different type of seige weapons available, and there is lots of nice tricks and tactics available to you; and keeps are a quite recent addition to the game, so I expect them to be improved and more polished at release or shortly following.</p>
<p>To sum up my experiences I would say this game is a blast.  The PVE aspect of it is great, much better than I anticipated.  The PVP is of course awesome.  PVP is so dynamic in nature that it can keep you entertained for a long while, and warhammer has so many PVP options and such variety in where and how you can fight I think this game will be a huge success.</p>
<p>Congrats Mythic, and thanks for the enjoyable year of beta testing =)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nazgum.com/2008/08/21/warhammer-beta-review/feed/</wfw:commentRss>
		</item>
		<item>
		<title>WAR Feature Cuts</title>
		<link>http://www.nazgum.com/2008/07/12/war-feature-cuts/</link>
		<comments>http://www.nazgum.com/2008/07/12/war-feature-cuts/#comments</comments>
		<pubDate>Sat, 12 Jul 2008 12:10:46 +0000</pubDate>
		<dc:creator>Nazgum</dc:creator>
		
		<category><![CDATA[MMORPGs]]></category>

		<category><![CDATA[Warhammer]]></category>

		<guid isPermaLink="false">http://www.nazgum.com/?p=317</guid>
		<description><![CDATA[I wanted to give myself a day to think about what the feature cuts meant before writing about them.  For anyone who somehow managed to miss this news, WAR is cutting 4 of its 6 capitols and 4 of its 24 classes to make their planned fall release.
Reactions to this around the web have been [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to give myself a day to think about what the <a title="http://mmorpg.com/gamelist.cfm/game/239/feature/2041" href="http://mmorpg.com/gamelist.cfm/game/239/feature/2041">feature cuts</a> meant before writing about them.  For anyone who somehow managed to miss this news, WAR is cutting 4 of its 6 capitols and 4 of its 24 classes to make their planned fall release.</p>
<p>Reactions to this around the web have been pretty mixed; <a title="http://thegreenskin.com/2008/07/11/announcements-of-mythical-proportions/" href="http://thegreenskin.com/2008/07/11/announcements-of-mythical-proportions/">Snafzg of The Greenskin</a> is pretty devastated, understandably as his site, which focuses on the Greenskins, just lost one of their classes and their capitol; <a title="http://waaagh.wordpress.com/2008/07/11/names-punks-and-cuts/" href="http://waaagh.wordpress.com/2008/07/11/names-punks-and-cuts/">Syp from Waaagh</a> seems mixed, mostly upset with how the news was delivered; and <a title="http://www.keenandgraev.com/" href="http://www.keenandgraev.com/">Keen from Keen and Graev</a> feels the game should have just been delayed again.</p>
<p>At first I was a little unsure how to react to this, but having a day to think about it, I feel the announcements mean mostly good things for WAR.</p>
<h3><strong>Capitol Cities Cut</strong></h3>
<p>First, having 4 of the 6 capitol cities sounds pretty devastating, but in reality it should have a pretty minor affect on the game, and be more positive than negative at launch.  WoW launched with 6 capitols, but 4 of them were incomplete and might as well have not been there.  Everyone just used Ogrimmar and Ironforge.  WAR will have just 2 cities, but they will hopefully be spectacular and full of things to do.  While leveling, you will share your one capitol with other factions, which should make it easier to meet up and find groups; and when the first few people get to 40, it will be easier to have a single target to focus on, rather than 3, since there will be fewer people available for attacking and defending.  Releasing the other cities at a later time seems to make more sense in this capacity, and releasing each as a finished city would be excellent.  These cuts seem to show Mythic is caring about Quality over Quantity, which is a much better position for long-term success.</p>
<h3><strong>Careers Cut</strong></h3>
<p>The career cuts hurt much more, because they have the potential to affect the balance of the game; each class should have a counter, and having Empire missing a tank with only 3 classes fighting Chaos which has the full 4 seems to raise quite a few issues (same issue exists but reversed with High Elves vs Dark Elves).  This game of course is not race vs race but faction vs faction, so it is not purely Chaos vs Empire, but Chaos, Greenskins and Dark Elves vs Empire, High Elves and Dwarfs.  This means it should be less of an issue, however, many may wish to follow their own races storyline, so the scenarios and battlefields available while leveling may well have some balance issues.</p>
<h3><strong>Silver Lining</strong></h3>
<p>Despite the balance issues for careers, I see a silver lining I haven&#8217;t seen mentioned on the other sites so far, and that is in the patches post release.  Looking at any other MMORPG, once the game is released, usually the patches post release are fairly underwhelming: mostly bugfixes and balancing with some occassional new content.  WAR however has a great opportunity here to keep patches post release interesting for a good while.  Having the game released and being able to look forward to a patch containing 2 new capitols, or 2 new careers is pretty exciting.  Providing they aim to keep a balance and offer them in bunches, there is still 4 patches there that would be very exciting post release.  Having those drop every 2 months would keep the releases interesting for 8 months, which should be just about when some major expansion news would begin showing up, stirring more interest.</p>
<p>Having the ability to release exciting patches for nearly a year post release may prove to be a bigger benefit to WAR than many anticipate; and hey, WoW released their game with no pve-endgame and no pvp, I am quite certain I will survive in WAR for a few months with 2 capitols, 3 fronts and 20 careers to explore.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nazgum.com/2008/07/12/war-feature-cuts/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Zenburn Color Scheme for Gedit</title>
		<link>http://www.nazgum.com/2008/07/06/zenburn-color-scheme-for-gedit/</link>
		<comments>http://www.nazgum.com/2008/07/06/zenburn-color-scheme-for-gedit/#comments</comments>
		<pubDate>Sun, 06 Jul 2008 11:39:53 +0000</pubDate>
		<dc:creator>Nazgum</dc:creator>
		
		<category><![CDATA[Gedit]]></category>

		<guid isPermaLink="false">http://www.nazgum.com/?p=315</guid>
		<description><![CDATA[I really love gedit, it is a great text editor and perfect for doing web development work; but I wasn&#8217;t too fond of most of the color schemes.  I wanted an easy on the eyes scheme similar to Zenburn&#8230; so I made one =)

Download the file from here: zenburn.xml
Then copy it to your ~/.gnome2/gedit/styles/ folder; [...]]]></description>
			<content:encoded><![CDATA[<p>I really love gedit, it is a great text editor and perfect for doing web development work; but I wasn&#8217;t too fond of most of the color schemes.  I wanted an easy on the eyes scheme similar to Zenburn&#8230; so I made one =)</p>
<p><img class="alignnone size-full wp-image-316" title="Zenburn Gedit Color Scheme" src="http://www.nazgum.com/wp-content/uploads/2008/07/zenburn.jpg" alt="Zenburn Gedit Color Scheme" width="597" height="512" /></p>
<p>Download the file from here: <a title="zenburn.xml" href="http://www.nazgum.com/files/zenburn.xml">zenburn.xml</a></p>
<p>Then copy it to your ~/.gnome2/gedit/styles/ folder; open gedit and in the Preferences -&gt; Fonts and Colors select Zenburn</p>
<p>Hope someone else enjoys it =)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nazgum.com/2008/07/06/zenburn-color-scheme-for-gedit/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Canadian DMCA: Friends Turned me into a $4,760,000 copyright criminal</title>
		<link>http://www.nazgum.com/2008/06/17/canadian-dmca-friends-turned-me-into-a-4760000-copyright-criminal/</link>
		<comments>http://www.nazgum.com/2008/06/17/canadian-dmca-friends-turned-me-into-a-4760000-copyright-criminal/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 13:46:20 +0000</pubDate>
		<dc:creator>Nazgum</dc:creator>
		
		<category><![CDATA[DRM]]></category>

		<guid isPermaLink="false">http://www.nazgum.com/?p=314</guid>
		<description><![CDATA[The Canadian DMCA, Bill C-61, will make it illegal to break any digital lock (DRM) with a $20,000 fine per infringement.
I legally purchased all 10 seasons of Friends.  My computer is hooked up to my TV.  Exercising my fair use rights (which apparently will no longer exist after this bill), I made a [...]]]></description>
			<content:encoded><![CDATA[<p><a title="http://www.michaelgeist.ca/content/view/3025/125/" href="http://www.michaelgeist.ca/content/view/3025/125/">The Canadian DMCA, Bill C-61</a>, will make it illegal to break any digital lock (DRM) with a $20,000 fine per infringement.</p>
<p>I legally purchased all 10 seasons of Friends.  My computer is hooked up to my TV.  Exercising my fair use rights (which apparently will no longer exist after this bill), I made a backup of every episode from the DVDs for personal use to watch from my computer.</p>
<p>Friends has 238 episodes.  Each episode was ripped individually into an AVI.  At $20,000 per infringement, I will apparently be a $4,760,000 copyright criminal!</p>
<p>Wow!  But that is apparently still better then the alternative.  Since I use the popular open-source operating system <a href="http://www.ubuntu.com/" title="http://www.ubuntu.com/">Ubuntu (Linux)</a>, which breaks the DRM on a DVD automatically with DeCSS each and every time you watch one, I would apparently be a $4.76M copyright criminal just from watching the episodes once from the DVD, and the infringement amount would continue to build each additional time i watched one.</p>
<p>In Industry Minister Jim Prentice&#8217;s own words, the bill is:</p>
<blockquote><p>a made-in-Canada approach that balances the needs of Canadian consumers and copyright owners, promoting culture, innovation and competition in the digital age.</p></blockquote>
<p>I think I may have to disagree with him.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nazgum.com/2008/06/17/canadian-dmca-friends-turned-me-into-a-4760000-copyright-criminal/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Searching a Model with merge_conditions</title>
		<link>http://www.nazgum.com/2008/06/15/searching-a-model-with-merge_conditions/</link>
		<comments>http://www.nazgum.com/2008/06/15/searching-a-model-with-merge_conditions/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 16:32:52 +0000</pubDate>
		<dc:creator>Nazgum</dc:creator>
		
		<category><![CDATA[Rails]]></category>

		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.nazgum.com/?p=313</guid>
		<description><![CDATA[Say you have a users resource with rails, and you have your index action like this:

class UsersController &#60; ApplicationController
  def index
    @users = User.search&#40; params.slice&#40;:name, :email, :gender&#41; &#41;
&#160;
    respond_to do &#124;format&#124;
      format.html
      format.xml &#123; render :xml =&#62; @users [...]]]></description>
			<content:encoded><![CDATA[<p>Say you have a users resource with rails, and you have your index action like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> UsersController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  <span style="color:#9966CC; font-weight:bold;">def</span> index
    <span style="color:#0066ff; font-weight:bold;">@users</span> = User.<span style="color:#9900CC;">search</span><span style="color:#006600; font-weight:bold;">&#40;</span> params.<span style="color:#9900CC;">slice</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:email</span>, <span style="color:#ff3333; font-weight:bold;">:gender</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    respond_to <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>format<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">html</span>
      <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">xml</span> <span style="color:#006600; font-weight:bold;">&#123;</span> render <span style="color:#ff3333; font-weight:bold;">:xml</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@users</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The User model can have a bunch of attributes, but the three we want to allow searching on are name, email and gender.  We pass those to the User model and now need to build out our query.  The problem however is that we only want to use the condition if it exists, and normally rails wants you to have one string, array or hash to pass in as the conditions.</p>
<p>If we try and use a hash, it seems to work well:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> search<span style="color:#006600; font-weight:bold;">&#40;</span>params = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    conditions = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
    conditions<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:name</span><span style="color:#006600; font-weight:bold;">&#93;</span>   = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:name</span><span style="color:#006600; font-weight:bold;">&#93;</span>   <span style="color:#9966CC; font-weight:bold;">unless</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:name</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
    conditions<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:email</span><span style="color:#006600; font-weight:bold;">&#93;</span>  = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:email</span><span style="color:#006600; font-weight:bold;">&#93;</span>  <span style="color:#9966CC; font-weight:bold;">unless</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:email</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
    conditions<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:gender</span><span style="color:#006600; font-weight:bold;">&#93;</span> = params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:gender</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:gender</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
&nbsp;
    find<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> conditions<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Except, we want to enable searching of users with the &#8220;LIKE&#8221; conditions, so searching for &#8220;j&#8221; will match all users whose name begins with j.  Now we have to switch to using a string or array as the conditions, and it gets more messy:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> search<span style="color:#006600; font-weight:bold;">&#40;</span>params = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    conditions = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    conditions<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">unless</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:name</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
      conditions<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">push</span> <span style="color:#996600;">&quot;name LIKE ?&quot;</span>
      conditions.<span style="color:#9900CC;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:name</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'%'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">unless</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:email</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
      conditions<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">push</span> <span style="color:#996600;">&quot;email = ?&quot;</span>
      conditions.<span style="color:#9900CC;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:email</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">unless</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:gender</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
      conditions<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">push</span> <span style="color:#996600;">&quot;gender = ?&quot;</span>
      conditions.<span style="color:#9900CC;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:gender</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    conditions<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> = conditions<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">' AND '</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    find<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> conditions<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The above code works, but its pretty messy.  We can make it cleaner using one of ActiveRecord&#8217;s methods, merge_conditions.  merge_conditions is the method rails calls to convert your conditions array into your sql statement, ie turning this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;name LIKE ? AND email = ? AND gender = ?&quot;</span>, <span style="color:#996600;">'joe'</span>, <span style="color:#996600;">'me@gmail.com'</span>, <span style="color:#996600;">'male'</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>Into this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#996600;">&quot;name LIKE 'joe%' AND email = 'me@gmail.com' AND gender = 'male'&quot;</span></pre></div></div>

<p>Armed with merge_conditions, we can then update the model to be much nicer:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> search<span style="color:#006600; font-weight:bold;">&#40;</span>params = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    cond = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    cond <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;name LIKE ?&quot;</span>, params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:name</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'%'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:name</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
    cond <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;email = ?&quot;</span>,   params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:email</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#93;</span>       <span style="color:#9966CC; font-weight:bold;">unless</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:email</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
    cond <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;gender = ?&quot;</span>,  params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:gender</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#93;</span>      <span style="color:#9966CC; font-weight:bold;">unless</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:gender</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
    conditions = cond.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>c<span style="color:#006600; font-weight:bold;">|</span> merge_conditions<span style="color:#006600; font-weight:bold;">&#40;</span>c<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">' AND '</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    find<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> conditions<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>To me this is much more readable and concise, similar to the Hash option but supporting LIKE.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nazgum.com/2008/06/15/searching-a-model-with-merge_conditions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Tracking Who’s Online with Ruby on Rails</title>
		<link>http://www.nazgum.com/2008/05/27/tracking-whos-online-with-ruby-on-rails/</link>
		<comments>http://www.nazgum.com/2008/05/27/tracking-whos-online-with-ruby-on-rails/#comments</comments>
		<pubDate>Tue, 27 May 2008 09:21:33 +0000</pubDate>
		<dc:creator>Nazgum</dc:creator>
		
		<category><![CDATA[AJAX]]></category>

		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.nazgum.com/?p=311</guid>
		<description><![CDATA[A common feature on many sites is showing who is currently online.  It&#8217;s a feature I added for MMO Guildsites, and showing how we did it seems like a perfect blog post for 2:30am on a Tuesday.  Here&#8217;s an example of how our Who&#8217;s Online looks:

Tracking who&#8217;s online is one of the features [...]]]></description>
			<content:encoded><![CDATA[<p>A common feature on many sites is showing who is currently online.  It&#8217;s a feature I added for <a href="http://www.mmoguildsites.com">MMO Guildsites</a>, and showing how we did it seems like a perfect blog post for 2:30am on a Tuesday.  Here&#8217;s an example of how our Who&#8217;s Online looks:</p>
<p><img src="http://www.nazgum.com/wp-content/uploads/2008/05/whos_online.png" alt="" title="whos_online" width="205" height="339" class="alignnone size-full wp-image-312" /></p>
<p>Tracking who&#8217;s online is one of the features you can easily over-think at first, but once you remember the web is not in real-time the solution is very simple.  On your site, you will likely have a users table (we called ours members, which is what i will use in this example) that has their information such as username, password, etc.  We want to add a session_time field to that table:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="ruby">ruby script<span style="color:#006600; font-weight:bold;">/</span>generate migration add_session_time_to_member session_time:datetime
rake db:migrate</pre></td></tr></table></div>

<p>With this field available, to find who is online we will search for members whose session_time is less than 5 minutes ago; so in our member model:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> Member <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">whos_online</span>
    find<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;session_time &gt; ?&quot;</span>, <span style="color:#006666;">5</span>.<span style="color:#9900CC;">minutes</span>.<span style="color:#9900CC;">ago</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Now launching the console we can quickly try it out, and it will return the members who are online:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">ruby script<span style="color:#006600; font-weight:bold;">/</span>console
Loading development environment <span style="color:#006600; font-weight:bold;">&#40;</span>Rails <span style="color:#006666;">2.0</span><span style="color:#006666;">.2</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> Member.<span style="color:#9900CC;">whos_online</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#008000; font-style:italic;"># we often fetch them for a site like this</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#0066ff; font-weight:bold;">@site</span>.<span style="color:#9900CC;">members</span>.<span style="color:#9900CC;">whos_online</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>Except, it will just return empty arrays since we have not set a session_time for any members yet.  To set the session_time, we want to update it to the current time whenever the member performs any action on the site (views a page, adds a post, logs in, etc.), so in application.rb we add a before_filter:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> ApplicationController <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>
  before_filter <span style="color:#ff3333; font-weight:bold;">:get_current_member</span>
&nbsp;
private
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> get_current_member
    <span style="color:#0066ff; font-weight:bold;">@current_member</span> = <span style="color:#0066ff; font-weight:bold;">@site</span>.<span style="color:#9900CC;">members</span>.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span>session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:member_id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:member_id</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@current_member</span>
      <span style="color:#008000; font-style:italic;"># other method calls..</span>
&nbsp;
      <span style="color:#008000; font-style:italic;"># update the session time</span>
      <span style="color:#0066ff; font-weight:bold;">@current_member</span>.<span style="color:#9900CC;">update_attribute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:session_time</span>, session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:session_time</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>In our before_filter, we grab the current member and then update their session_time.  But this is not a very good solution as every action does a database write for the session_time.  Since we are only checking if the session_time is less than 5 minutes, we only need to update the session once every 5 minutes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> ApplicationController <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>
  before_filter <span style="color:#ff3333; font-weight:bold;">:get_current_member</span>
&nbsp;
private
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> get_current_member
    <span style="color:#0066ff; font-weight:bold;">@current_member</span> = <span style="color:#0066ff; font-weight:bold;">@site</span>.<span style="color:#9900CC;">members</span>.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span>session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:member_id</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:member_id</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@current_member</span>
      <span style="color:#008000; font-style:italic;"># other method calls..</span>
&nbsp;
      <span style="color:#008000; font-style:italic;"># update the session time if its been updated less than 5 minutes ago</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:session_time</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#9966CC; font-weight:bold;">or</span> session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:session_time</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&lt;</span>= <span style="color:#006666;">5</span>.<span style="color:#9900CC;">minutes</span>.<span style="color:#9900CC;">ago</span>
        session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:session_time</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
        <span style="color:#0066ff; font-weight:bold;">@current_member</span>.<span style="color:#9900CC;">update_attribute</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:session_time</span>, session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:session_time</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>This way is much improved, since now we are only doing a database write once every 5 minutes rather then every request and still providing the same functionality.  With this in place, our members have a session_time that is updated while they are active on the site, and we can easily fetch active members to check Who&#8217;s Online.</p>
<p>One last nice thing that would be nice to have is the Who&#8217;s Online display auto-updating with AJAX.  Using prototype and rails this is pretty easy, first ensure prototype is loaded in your main layout:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby"><span style="color:#006600; font-weight:bold;">&lt;%</span>= javascript_include_tag <span style="color:#ff3333; font-weight:bold;">:defaults</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span></pre></td></tr></table></div>

<p>Then in your Who&#8217;s Online view, you will set it up similar to this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;whos_online&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span>%= render :partial =<span style="font-weight: bold; color: black;">&gt;</span></span> &quot;whos_online&quot; -%&gt;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/div<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span>%= periodically_call_remote :frequency =<span style="font-weight: bold; color: black;">&gt;</span></span> 300, 
            :url =&gt; {:controller =&gt; &quot;whos_online&quot;, :action =&gt; &quot;update&quot;}, 
            :method =&gt; 'get' %&gt;</pre></td></tr></table></div>

<p>And the method in your controller to handle this call:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="ruby"><span style="color:#9966CC; font-weight:bold;">class</span> WhosOnlineController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  <span style="color:#9966CC; font-weight:bold;">def</span> update
    <span style="color:#0066ff; font-weight:bold;">@whos_online</span> = <span style="color:#0066ff; font-weight:bold;">@site</span>.<span style="color:#9900CC;">members</span>.<span style="color:#9900CC;">whos_online</span>
&nbsp;
    respond_to <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>format<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">js</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>And finally the update view for this, update.js.rjs</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby">page<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;whos_online&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">replace_html</span> <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'whos_online'</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.nazgum.com/2008/05/27/tracking-whos-online-with-ruby-on-rails/feed/</wfw:commentRss>
		</item>
		<item>
		<title>IE Caching AJAX requests</title>
		<link>http://www.nazgum.com/2008/05/18/ie-caching-ajax-requests/</link>
		<comments>http://www.nazgum.com/2008/05/18/ie-caching-ajax-requests/#comments</comments>
		<pubDate>Sun, 18 May 2008 22:37:25 +0000</pubDate>
		<dc:creator>Nazgum</dc:creator>
		
		<category><![CDATA[AJAX]]></category>

		<category><![CDATA[IE]]></category>

		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://nazgum.com/?p=299</guid>
		<description><![CDATA[If your website makes AJAX calls, you&#8217;ve likely run into the problem of IE caching the AJAX request; this is almost never the behavior you want, as most AJAX calls are for updating parts of a page with new content and you would not want them to return an outdated version.
A common way to fix [...]]]></description>
			<content:encoded><![CDATA[<p>If your website makes AJAX calls, you&#8217;ve likely run into the problem of IE caching the AJAX request; this is almost never the behavior you want, as most AJAX calls are for updating parts of a page with new content and you would not want them to return an outdated version.</p>
<p>A common way to fix this is to make all your AJAX requests with POST, except this breaks REST and is a less than ideal solution, especially if you are using Ruby on Rails.</p>
<p>David Rupp <a title="http://davidrupp.blogspot.com/2008/02/ie-misbehaving-fix-it-with-prototype.html" href="http://davidrupp.blogspot.com/2008/02/ie-misbehaving-fix-it-with-prototype.html">came up with a great solution</a>, making use of Prototype&#8217;s wrap function to add an If-Modified-Since header to every AJAX request, which IE does obey and will then ensure IE is not caching your AJAX requests.</p>
<p>After you load prototype.js, just add the following javascript (in application.js would be a good spot, if its a rails app):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript"><span style="color: #009900; font-style: italic;">// Defeat IE caching AJAX bug</span>
Ajax.<span style="color: #006600;">Request</span>.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">setRequestHeaders</span> =
Ajax.<span style="color: #006600;">Request</span>.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">setRequestHeaders</span>.<span style="color: #006600;">wrap</span><span style="color: #66cc66;">&#40;</span>
<span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>original<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">transport</span>.<span style="color: #006600;">setRequestHeader</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;If-Modified-Since&quot;</span>, <span style="color: #3366CC;">&quot;Thu, 1 Jan 1970 00:00:00 GMT&quot;</span><span style="color: #66cc66;">&#41;</span>;
original<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #009900; font-style: italic;">// then call the original version</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>And IE now no longer caching your AJAX requests, thanks David =)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nazgum.com/2008/05/18/ie-caching-ajax-requests/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
