<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>notkeepingitreal.com: Category Rails</title>
    <link>http://notkeepingitreal.com/articles/category/rails</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Um, Did I Ever Talk About What the Hell Rails Actually Is?</title>
      <description>&lt;p&gt;So two people, which in the world of the readers of this blog, corresponds to about the size of the Northern Hemisphere, have read and been confused about this &lt;em&gt;rails&lt;/em&gt; thing. They and I know that &lt;a href="http://www.google.com"&gt;the internet&lt;/a&gt; is out there to help, but it&amp;#8217;s probably expecting a lot for people to leave the comfort of their &lt;a href="http://notkeepingitreal.com"&gt;source for news on everything&lt;/a&gt;. It&amp;#8217;s time to set the record straight and clarify &lt;em&gt;what exactly it is&lt;/em&gt; that I keep going &lt;a href="http://notkeepingitreal.com/articles/category/rails"&gt;on&lt;/a&gt; and &lt;a href="http://notkeepingitreal.com/articles/category/railsconf"&gt;on&lt;/a&gt; about.&lt;/p&gt;


	&lt;p&gt;Rails, short for &lt;a href="http://rubyonrails.org"&gt;Ruby on Rails&lt;/a&gt;, is, as it turns out, a web development framework. It was created in &lt;a href="http://www.loudthinking.com/arc/000200.html"&gt;2004 or thereabouts&lt;/a&gt; by a &lt;a href="http://www.loudthinking.com/about.html"&gt;person&lt;/a&gt; who &lt;a href="http://dhhtalksfunny.com"&gt;talks funny&lt;/a&gt;. Rails was built using a programming language called (surprise) &lt;a href="http://www.ruby-lang.org"&gt;Ruby&lt;/a&gt;, which has incidentally been around for much longer (publicly released in 1995).&lt;/p&gt;


	&lt;p&gt;The great thing about web development is that you can write programs that are &lt;a href="http://www.joelonsoftware.com/articles/APIWar.html"&gt;available on any reasonable computer on the planet&lt;/a&gt;. One unfortunate characteristic of software development in general &amp;#8211; and web development in particular &amp;#8211; is that easy things often turn out to be &lt;a href="http://www.theserverside.com/news/thread.tss?thread_id=24803#115994"&gt;pretty damn hard&lt;/a&gt;.  Web development frameworks try to help us avoid this unfortunate state of affairs. The great thing about rails is that it actually makes web development a pretty good time for developers. Rails attempts, with a fair degree of success in my mind, to make the easy things easy and the hard things attainable. Ruby (that&amp;#8217;s the language, remember) is also not to be neglected any time &amp;#8220;programming&amp;#8221; and &amp;#8220;fun&amp;#8221; happen to be used in the same breath, since rails obviously wouldn&amp;#8217;t have been possible without it.&lt;/p&gt;


	&lt;p&gt;And now that our ducks are in a row, go enjoy &lt;a href="http://rubyonrails.org"&gt;rails&lt;/a&gt;!&lt;/p&gt;</description>
      <pubDate>Wed, 17 Jan 2007 20:18:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:5e00106c-32d7-4e32-be45-ba70b08d5137</guid>
      <author>Kevin</author>
      <link>http://notkeepingitreal.com/articles/2007/01/17/um-did-i-ever-talk-about-what-the-hell-rails-actually-is</link>
      <category>Rails</category>
      <category>Struggle</category>
      <category>Software</category>
      <trackback:ping>http://notkeepingitreal.com/articles/trackback/1568</trackback:ping>
    </item>
    <item>
      <title>Turning to the Dark Side - Checking out Django</title>
      <description>&lt;p&gt;Working with ruby on rails for a while has made me curious about django, the web development framework written in ruby&amp;#8217;s buddy language, python. The tipping point for actually checking it out came after my friend &lt;a href="http://langeman.net/"&gt;Matt Langeman&lt;/a&gt; told me about the &lt;a href="http://www.djangobook.com/en/beta/"&gt;django beta book&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;So I&amp;#8217;m rocking along with the book, which is luckily very hands-on. The good stuff begins in &lt;a href="http://www.djangobook.com/en/beta/chapter02"&gt;chapter two&lt;/a&gt;, where they go over how to set up your system to actually run django.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ve already got python:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
&amp;gt; python
Python 2.4.3 (#2, Oct  6 2006, 07:52:30)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;So on to this django framework itself. Somewhere near the beginning of chapter two, the authors say that &amp;#8220;Most people will want to install the latest official release.&amp;#8221; I will soon begin to doubt this when I see the number of errors that can be produced by &lt;em&gt;simply following along with the examples&lt;/em&gt; in the book (granted, some of these struggles certainly have to do with my specific environment). Anyway, onwards:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
&amp;gt; wget http://www.djangoproject.com/download/0.95/tarball/
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;I unpack the app, create a project and run: &amp;#8220;python manage.py runserver&amp;#8221; and I&amp;#8217;m off to the races and &amp;#8230; no wait, I can&amp;#8217;t hit anything on 127.0.0.1 since I&amp;#8217;m not running locally.&lt;/p&gt;


	&lt;p&gt;How about &amp;#8220;python manage.py runserver 0.0.0.0:8000&amp;#8221; ... much better. I manage to arrive at the welcome page in my browser: &amp;#8220;It worked! Congratulations on your first Django-powered page.&amp;#8221;&lt;/p&gt;


	&lt;p&gt;While moving through &lt;a href="http://www.djangobook.com/en/beta/chapter03/"&gt;chapter three&lt;/a&gt; and setting up urls.py (some sort of distant relative of rails routes), I&amp;#8217;m slapped with the error: &amp;#8220;ImportError at /now/ No module named mysite.views&amp;#8221;.&lt;/p&gt;


	&lt;p&gt;Damn, I didn&amp;#8217;t call my project &amp;#8220;mysite&amp;#8221; like a good tutorial-follower. I change &amp;#8220;mysite to &amp;#8220;survey&amp;#8221; in urls.py and I&amp;#8217;m golden again for a minute&amp;#8230;&lt;/p&gt;


	&lt;p&gt;After a very short minute, I get &amp;#8220;AttributeError at /now/ &amp;#8216;function&amp;#8217; object has no attribute &amp;#8216;rindex&amp;#8217;&amp;#8221;.&lt;/p&gt;


	&lt;p&gt;Someone from django-users@googlegroups has apparently had this issue before, and I get referred to &lt;a href="http://www.djangoproject.com/documentation/url_dispatch/"&gt;the django docs&lt;/a&gt;. I discover that the cool kids (or maybe just the kids that aren&amp;#8217;t using django edge) use a string for the second argument of the so-called &amp;#8220;tuple.&amp;#8221;&lt;/p&gt;


	&lt;p&gt;Bad:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
(r'^now/$', current_datetime),
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Good:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
(r'^now/$', 'survey.views.current_datetime'),
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;The page loads, displaying the current time. The book reminds me that I have just created my first dynamic page with django. Fair enough.&lt;/p&gt;


So I&amp;#8217;m rolling along in &lt;a href="http://www.djangobook.com/en/beta/chapter04/"&gt;chapter four&lt;/a&gt; by now, and the authors are wanting me to start up the interactive python interpreter by typing &amp;#8220;python,&amp;#8221; which I do. I also type: &amp;#8220;from django.template import Template&amp;#8221;, but am greeted with an error:                                                                                                                                                                            
&lt;pre&gt;
&lt;code&gt;
raise EnvironmentError, "Environment variable %s is undefined." % ENVIRONMENT_VARIABLE
EnvironmentError: Environment variable DJANGO_SETTINGS_MODULE is undefined.
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Apparently i was supposed to set up this environment variable before firing up my interactive python client. After running: &amp;#8220;export &lt;span class="caps"&gt;DJANGO&lt;/span&gt;_SETTINGS_MODULE=survey.settings&amp;#8221; on the command line (where survey is the name of the project I created), I try to import Template again. &lt;span class="caps"&gt;ERROR&lt;/span&gt;: &amp;#8220;EnvironmentError: Could not import settings &amp;#8216;survey.settings&amp;#8217; (Is it on sys.path? Does it have syntax errors?): No module named survey.settings&amp;#8221;. So at this point I&amp;#8217;m wondering why God doesn&amp;#8217;t love me. Someone with a searchable chat archive, however, does love me. I&amp;#8217;m told to run:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
export PYTHONPATH=~
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;This apparently worked because my django project was one level below my home directory. I finally get the simple interactive python example to work.&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://www.djangobook.com/en/beta/chapter04/"&gt;Chapter four&lt;/a&gt; is all about django&amp;#8217;s templating system. One distinguishing feature of django templates is that they are limited. Rails templates allow arbitrary ruby code, whereas their django counterparts allow variable injection, looping, and other assorted goodies, but do not evaluate &lt;strong&gt;just any&lt;/strong&gt; python code you throw between {% %} tags.&lt;/p&gt;


	&lt;p&gt;So as I&amp;#8217;m getting ready to use my first real template in a separate file, I need to set up the path to my templates. I try to do it the cool-guy way:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
TEMPLATE_DIRS = (
    os.path.join(os.path.basename(__file__), 'templates'),
)
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;And I get an error when I try to hit a page: &amp;#8220;NameError: name &amp;#8216;os&amp;#8217; is not defined&amp;#8221;. Not cool. Luckily the fix is simple. I add the line &amp;#8220;import os&amp;#8221; before setting up &lt;span class="caps"&gt;TEMPLATE&lt;/span&gt;_DIRS in the settings.py file. No more errors, so I throw the sample template current_datetime.html into the templates directory and try to fire up the page in my browser:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
TemplateDoesNotExist at /now/
current_datetime.html
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;The &amp;#8220;Template-loader postmortem&amp;#8221; that comes up in my browser seems to be telling me that it&amp;#8217;s trying the find the file under settings.pyc/templates/, which seems wrong. So hell, I want to get back to the book, and I don&amp;#8217;t &lt;em&gt;have&lt;/em&gt; to be a cool-kid at the moment &amp;#8211; I&amp;#8217;ve probably got some time here before rolling out my first production django site &amp;#8211; I hardcode the absolute path for &lt;span class="caps"&gt;TEMPLATE&lt;/span&gt;_DIRS. Bingo: fixed.&lt;/p&gt;


	&lt;p&gt;In talking about templates, the authors make a statement that sounds slightly more than controversial for someone coming from a rails worldview: &amp;#8220;Because that&amp;#8217;s business logic, it belongs in the view.&amp;#8221; This highlights a major difference in language between the rails and django clans. The authors really wanted to make the point that business logic does not belong in the &lt;strong&gt;template&lt;/strong&gt; (which is basically what rails folks would call a &amp;#8220;view&amp;#8221;). The way django relates to &lt;span class="caps"&gt;MVC&lt;/span&gt; (or &lt;span class="caps"&gt;MTV&lt;/span&gt; as they sometimes seem to call it) is clarified a bit more in &lt;a href="http://www.djangobook.com/en/beta/chapter05/"&gt;chapter five&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;As I&amp;#8217;m reading along, I learn that &amp;#8220;python manage.py shell&amp;#8221; is the equivalent of rails&amp;#8217; &amp;#8221;./script/console&amp;#8221;. I&amp;#8217;m also able to connect to the MySQL database on my box successfully from the python prompt &lt;em&gt;with the django settings&lt;/em&gt; on my first try. Sweet. I&amp;#8217;m patting myself on the back when the book blindsides me with a note that I have not yet created a django app. &lt;em&gt;Mutter &amp;#8230; I could have sworn that I&lt;/em&gt; ... . The authors patiently explain to me that an &amp;#8220;app&amp;#8221; is a portable set of django functionality, and that I must create an app in order to make use of django&amp;#8217;s &lt;strong&gt;models&lt;/strong&gt;. I&amp;#8217;m right about at the point where&amp;#8217;s I&amp;#8217;m ready to go create an app on the command line when I realize that, &lt;em&gt;ohmygod, the funny things in the left margin of this book are comments!&lt;/em&gt; Man I bet that would have been useful. :) It seems like the authors probably could have said one or two things about the comments on the first page of the book &amp;#8211; or maybe they assumed that people were paying attention&amp;#8230;&lt;/p&gt;


	&lt;p&gt;In any case, this django stuff is a good time. I will likely continue on with creating an app, connecting to a database, and all sorts of delightful things in chapter five and beyond, but I&amp;#8217;ll try to keep my two cents contained to the comments in &lt;a href="http://www.djangobook.com/en/beta"&gt;the book&lt;/a&gt;. Your two cents can go in the comments below.&lt;/p&gt;</description>
      <pubDate>Sun, 07 Jan 2007 15:00:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:3dd83aaa-f877-4d88-8a6a-f298b2bc2a84</guid>
      <author>Kevin</author>
      <link>http://notkeepingitreal.com/articles/2007/01/07/turning-to-the-dark-side-checking-out-django</link>
      <category>Django</category>
      <category>Software</category>
      <category>Rails</category>
      <category>Experimentation</category>
      <trackback:ping>http://notkeepingitreal.com/articles/trackback/1566</trackback:ping>
    </item>
    <item>
      <title>Don't Get Hosed</title>
      <description>&lt;p&gt;&lt;a href="http://weblog.rubyonrails.org/2006/8/9/rails-1-1-5-mandatory-security-patch-and-other-tidbits"&gt;Upgrade rails today!&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 09 Aug 2006 15:39:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:0c593396-e7ea-480f-b9dd-3e10a12bc429</guid>
      <author>Kevin</author>
      <link>http://notkeepingitreal.com/articles/2006/08/09/dont-get-hosed</link>
      <category>Rails</category>
      <category>Struggle</category>
      <trackback:ping>http://notkeepingitreal.com/articles/trackback/36</trackback:ping>
    </item>
    <item>
      <title>Huh</title>
      <description>&lt;p&gt;Well, it kind of seems as if Typo is working with the &lt;a href="http://weblog.rubyonrails.org/articles/2006/04/09/rails-1-1-2-tiny-fix-for-gems-dependencies"&gt;rails of the day&lt;/a&gt;. Sweet.&lt;/p&gt;</description>
      <pubDate>Thu, 20 Apr 2006 00:13:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:0ef38bfb-37fa-4397-90d7-fcffefb3b865</guid>
      <author>Kevin</author>
      <link>http://notkeepingitreal.com/articles/2006/04/20/huh</link>
      <category>Rails</category>
    </item>
  </channel>
</rss>
