<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: date_select code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 16:00:41 GMT</pubDate>
    <description>DZone Snippets: date_select code</description>
    <item>
      <title>date_select conversion</title>
      <link>http://snippets.dzone.com/posts/show/5376</link>
      <description>function to convert a value from a date_select into a more sql-friendly value&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;%=date_select(:date,'',:start_year =&gt; 1950,:include_blank =&gt; false, :default =&gt; { :year =&gt; '1970' })%&gt;&lt;br /&gt;&lt;br /&gt;def convert_date(obj) &lt;br /&gt;  return &#8220;#{obj[&#8216;(1i)&#8217;]}-#{obj[&#8216;(2i)&#8217;]}-#{obj[&#8216;(3i)&#8217;]}&#8221; &lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 17 Apr 2008 13:20:35 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5376</guid>
      <author>indiehead (John)</author>
    </item>
    <item>
      <title>Use rails date_select without activerecord model</title>
      <link>http://snippets.dzone.com/posts/show/4630</link>
      <description>// In your view:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;%= date_select('range', 'start_date', :order =&gt; [:month, :day, :year])%&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;// In your controller:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;@start_date = Date.civil(params[:range][:"start_date(1i)"].to_i,params[:range][:"start_date(2i)"].to_i,params[:range][:"start_date(3i)"].to_i)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Credit: http://www.jonsthoughtsoneverything.com/2006/05/21/how-to-access-date_select-without-an-active-record-model/</description>
      <pubDate>Wed, 10 Oct 2007 12:42:58 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4630</guid>
      <author>davenolan (davenolan)</author>
    </item>
    <item>
      <title>Javascript code to set Rails date_select to today.</title>
      <link>http://snippets.dzone.com/posts/show/3146</link>
      <description>If you are using date_select in rails here is a little bit of javascript so that at the side of the fields the user can click a link that will automatically set the fields to todays date.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Updated: Now works on rails 1.2, as date_select now finally has ids&lt;/b&gt; &lt;br /&gt;&lt;code&gt;&lt;br /&gt;# put is app_root/public/javascript/application.js&lt;br /&gt;&lt;br /&gt;function set_today(model, atrib)&lt;br /&gt;{&lt;br /&gt;    t3 = document.getElementById(model + '_' + atrib + '_3i');&lt;br /&gt;    var dt = new Date(); &lt;br /&gt;    t3.selectedIndex = dt.getDate();&lt;br /&gt;	&lt;br /&gt;    t2 = document.getElementById(model + '_' + atrib + '_2i')&lt;br /&gt;    t2.selectedIndex = dt.getMonth() + 1;&lt;br /&gt;    &lt;br /&gt;    t1 = document.getElementById(model + '_' + atrib + '_1i')&lt;br /&gt;&lt;br /&gt;    for (i = 0; i &lt; t1.length; i++)&lt;br /&gt;	       {&lt;br /&gt;	           if (t1.options[i].text == dt.getFullYear())&lt;br /&gt;	           {&lt;br /&gt;	               t1.selectedIndex = i;&lt;br /&gt;	          }&lt;br /&gt;    } &lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To call this method say in a link use this in your rhtml&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;a href="javascript: set_today('model_name', 'column_name');"&gt;today?&lt;/a&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 13 Dec 2006 20:45:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3146</guid>
      <author>mrblack (Andy)</author>
    </item>
  </channel>
</rss>
