<?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"
	>

<channel>
	<title>Beige Sunshine</title>
	<atom:link href="http://blog.beigesunshine.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.beigesunshine.com</link>
	<description>Welcome to your head.</description>
	<pubDate>Wed, 04 Jun 2008 20:53:08 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Extremely Simple Calendar Integration for Rails</title>
		<link>http://blog.beigesunshine.com/2007/08/08/extremely-simple-calendar-integration-for-rails/</link>
		<comments>http://blog.beigesunshine.com/2007/08/08/extremely-simple-calendar-integration-for-rails/#comments</comments>
		<pubDate>Wed, 08 Aug 2007 17:49:51 +0000</pubDate>
		<dc:creator>mendicant</dc:creator>
		
		<category><![CDATA[rails]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://blog.beigesunshine.com/2007/08/08/extremely-simple-calendar-integration-for-rails/</guid>
		<description><![CDATA[Today we&#8217;ll go over an extremely simple way to add a javascript/css calendar to your Rails app. We will be using the Calendar Date Select Plugin. It is a small, easy to use calendar based on the prototype library.
This was written back in the day for Rails 1.2, so take all this information with a [...]]]></description>
			<content:encoded><![CDATA[<p>Today we&#8217;ll go over an extremely simple way to add a javascript/css calendar to your Rails app. We will be using the <a href="http://code.google.com/p/calendardateselect/">Calendar Date Select Plugin</a>. It is a small, easy to use calendar based on the prototype library.</p>
<p>This was written back in the day for Rails 1.2, so take all this information with a grain of salt.</p>
<p>Installation is simple, and uses the typical installation syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="bash">script<span style="color: #000000; font-weight: bold;">/</span>plugin <span style="color: #c20cb9; font-weight: bold;">install</span> http:<span style="color: #000000; font-weight: bold;">//</span>calendardateselect.googlecode.com<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>tags<span style="color: #000000; font-weight: bold;">/</span>calendar_date_select</pre></div></div>

<p>Voila! Installed!</p>
<p>Now, we just need to integrate it.</p>
<p>First, in your layout you need to add the javascript tag:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#006600; font-weight:bold;">&amp;</span>lt;<span style="color:#006600; font-weight:bold;">%</span>= calendar_date_select_includes <span style="color:#996600;">&quot;silver&quot;</span> <span style="color:#006600; font-weight:bold;">%&amp;</span>gt;</pre></div></div>

<p>You can also use &#8220;red&#8221;, &#8220;blue&#8221; or &#8220;nil&#8221; for other color schemes.</p>
<p>Also note that you need to have prototype included as well, so if you haven&#8217;t already, you should also add the following to your layout:</p>

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

<p>And now, we&#8217;re ready to use it! Usage is simple. I was using it to keep track of an expiry date for a property, so I used to the following tag:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#006600; font-weight:bold;">&amp;</span>lt;<span style="color:#006600; font-weight:bold;">%</span>= calendar_date_select_tag <span style="color:#996600;">&quot;property[expiry_date]&quot;</span>, <span style="color:#0066ff; font-weight:bold;">@property</span>.<span style="color:#9900CC;">expiry_date</span>.<span style="color:#9900CC;">to_s</span>  <span style="color:#006600; font-weight:bold;">%&amp;</span>gt;</pre></div></div>

<p>If you wish, you can also check out the <a href="http://www.restatesman.com/static/calendar">demo</a> section for more information on using it with Form Builder.</p>
<p>Finally, I didn&#8217;t like the default &#8216;natural&#8217; syntax for the date &#8220;August 8th, 2007&#8243;, so I changed it to use my preference, hyphenated syntax. To do this, open your environment.rb file and add the following line:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">CalendarDateSelect.<span style="color:#CC0066; font-weight:bold;">format</span> = <span style="color:#ff3333; font-weight:bold;">:hyphen_ampm</span></pre></div></div>

<p>There! That is all I needed to do. Of course, there are more options, simply adding a :time =&gt; true will allow you to have a time field as well. There are a few more configuration options available for the calendar. You can find out more and get some more screenshots by visiting the project&#8217;s <a href="http://code.google.com/p/calendardateselect/">homepage</a>.</p>
<p><strong>Update:</strong><br />
Sorry, I haven&#8217;t responded to basically anyone that has commented here. I wish I had more time, but at this point I don&#8217;t. I am planning on getting back into this, but it might take a while. :(</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.beigesunshine.com/2007/08/08/extremely-simple-calendar-integration-for-rails/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Cascading Selects in Rails</title>
		<link>http://blog.beigesunshine.com/2007/07/18/cascading-selects-in-rails/</link>
		<comments>http://blog.beigesunshine.com/2007/07/18/cascading-selects-in-rails/#comments</comments>
		<pubDate>Wed, 18 Jul 2007 23:07:32 +0000</pubDate>
		<dc:creator>mendicant</dc:creator>
		
		<category><![CDATA[rails]]></category>

		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.beigesunshine.com/2007/07/18/cascading-selects-in-rails/</guid>
		<description><![CDATA[While I know there are resources out there for creating Cascading (dependant?) select boxes using Ruby on Rails, my decision to write about this came more from the myriad of solutions for all different versions of rails. Some of them worked and some of them didn&#8217;t.  This is what ended up being my solution [...]]]></description>
			<content:encoded><![CDATA[<p>While I know there are resources out there for creating Cascading (dependant?) select boxes using Ruby on Rails, my decision to write about this came more from the myriad of solutions for all different versions of rails. Some of them worked and some of them didn&#8217;t.  This is what ended up being my solution to the problem.</p>
<p>As a background, this was for a signup page which would require a state/province and a country. I wanted a user to select their country first, which would then populate the select box for the state/province so that they could choose from only relevant entries.</p>
<p>The model is Property and the controller is properties_controller.<br />
The relevant part of the form looks like this:</p>
<pre>
<code>&lt;%= select "property", "country_id", Country.find(:all).collect {|c| [ c.name, c.id ] }, { :include_blank =&gt; true} %&gt;
&lt;div id="provinces"&gt;
  &lt;%= select "property", "province_id", @provinces.collect {|p| [ p.name, p.id ] }, { :include_blank =&gt; true } %&gt;&lt;/td&gt;
&lt;/div&gt;
&lt;script type="text/javascript"&gt;
  //&lt;![CDATA[
  new Form.Element.Observer('property_country_id', 0, function(element, value) { new Ajax.Request('/properties/select_country?country_id='+value, {asynchronous:true, evalScripts:true}); });
  //]]&gt;
&lt;/script&gt;</code>
</pre>
<p>Now, there is some clarification needed here. I would guess that people would argue that rather than write your own javascript in this instance, it would make more sense to use the observe_field helper. I could not for the life of me get the observe_field helper to create working javascript. If anyone has any suggestions, I&#8217;d be happy to hear them.Anyhow, the basics of the javascript is this:<br />
Observe the field &#8216;property_country_id&#8217;.<br />
When it is changed, perform the listed function.</p>
<p>The function creates an Ajax Request to my properties controller to it&#8217;s select_country action, and also passes in the country_id selected in the parameters.</p>
<p>Now let&#8217;s look at how the action works in app/controllers/properties_controller.rb.</p>
<pre>
<code>def select_country
  @country_id=params[:country_id]

  if (@country_id.nil?)
    @provinces=Array.new
  else
    @provinces = Province.find(:all, :conditions =&gt; 'country_id='+@country_id, :order=&gt;'name')
  end
end</code>
</pre>
<p>What this does is checks the country_id and if it doesn&#8217;t  exist returns a new empty array, and if it does exist, finds all the provinces (I&#8217;m Canadian so I named my model provinces) related to that country.So now we have the the list of provinces, and all thats left for us to do is repopulate the Province Select box. To do that, we use an RJS template. So we create a .rjs file in app/views/properties/select_country.rjs. We then populate it with:</p>
<p>page.replace_html(&#8217;provinces&#8217;, (select &#8220;property&#8221;, &#8220;province_id&#8221;, @provinces.collect {|p| [ p.name, p.id ] }, { :include_blank => true }) )</p>
<p>This will replace the html in the id &#8216;provinces&#8217; with a select box populated with the provinces we found in the action.</p>
<p>That&#8217;s all there is to it!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.beigesunshine.com/2007/07/18/cascading-selects-in-rails/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
