Tag Archive for 'ruby on rails'

YUI TreeView with Ruby on Rails

Here’s some code I’m using to generate a dynamic tree view using an acts_as_tree model with slug and title fields, the TreeView widget from YUI, and a Rails helper. I chopped out some of the code for clarity, so all this does is create a menu with the titles from the model, but the basic idea is there to expand on.

Rails view/JavaScript

<script type="text/javascript">
  var page_tree;
  page_tree_init = function () {
    page_tree = new YAHOO.widget.TreeView('page_tree');
    var root = page_tree.getRoot();
    <% generate_page_nodes(@root) {} %>
    page_tree.draw();
  };
  page_tree_init();
</script>

Ruby

def generate_page_nodes(node, &block)
  parent = node.parent
  node_name = node.slug.gsub('-', '_')
  parent_node_name = parent.nil? ? 'root' : parent.slug.gsub('-', '_')
  js = <<-JS
    var #{node_name} = new YAHOO.widget.MenuNode('<span class="node_title">#{node.title}</span>',
                                                 #{parent_node_name});
  JS
  concat(js, block.binding)
  children = node.children
  children.each { |c| generate_page_nodes(c, &block) } unless children.empty?
end

Ruby on Rails… Revisited

Updated with links and a couple typo corrections.

I’ve been working on a fairly big Web site project lately. My partner and I initially decided to use Django to build the site, mainly because I’m a Python “expert” and Django is (apparently) the #1 Python Web framework. We were also lured by the easy admin interface.

After trying to use Django and not really enjoying it, I tried switching to Pylons because I’ve had a good amount of experience with it in the building of byCycle.org. It’s gone through two fairly major releases since then, and so have a bunch of the libraries that tend to get used with it, like SQLAlchemy, Elixir, etc.

I was having a hard time with the Pylons docs, and so I ended screwing around with Grok (which actually looks fairly interesting) and even took a look at the Zope 3 site. I’m sure Zope is really awesome or whatever, but it might as well suck. Every time I look at that site, I’m just like “WTF! This shit has been around for like five years!” Anyway, I might just not be smart enough for Zope.

This led us back toward Rails (even if it is a ghetto). I used Rails a bit last year but never did anything too serious with it. Diving into it today was quite a pleasure. There are issues to be sure, but overall I’m enjoying it by far over any of the other options we had tried. I’m also enjoying learning/relearning Ruby.

If Pylons had good docs, we’d probably be using that.

So, I don’t know if this is a particularly useful post, since I didn’t get into much in the way of reasons (what, i have back this up?!). This subject’s been hashed and rehashed, but I just wanted (needed) to make a qualitative statement about my/our experience, which, of course, is purely personal.

I Like Mephisto

Update 3/20/08: As it turns out, though Mephisto has some neato features, it’s not so great over all. Seems to be somewhat of a sinking ship. I also had this to say about it over on the old blog before I switched everything over to WordPress:

3/18/08 @ 4:10pm: I’m revamping my site. What could be more exciting?! All new posts will be written over here. This site will stay active until I can find the time to migrate all the old posts to the new site.

As noted, this site is “powered by” Mephisto. This is my first time using it, and I must say that it’s got “the beat” (that is, it rocks). Previously, I’ve used WordPress for blogging and as a lightweight content management system, but I must say that I like Mephisto much better, and hosts like WebFaction make setting up a Rails app super easy (and for only slightly more $/mo. than a typical PHP/MySQL hosting company).

I was interested in Typo, but their site has been “coming soon” for a long time now. Also, on WebFaction, you can install Mephisto by clicking a few times and typing a name for your install. This is possible because WebFaction has an API for custom install scripts, which is, if you ask me, a brilliant idea. If you’ve already got an account, you can click here to install Mephisto.

Update 3/20/2008: This was written in January of 2007. Currently, I am working freelance while looking for a new job. I have a couple of prospects, but I am still open to other opportunities. What follows is still somewhat pertinent, but I’m no longer interested in relocation and I haven’t done much with Java lately.

I am officially looking for a job—in particular, a software development job. I’m willing to relocate, especially to the Northeast (as in New England, not NE Portland). I’m also willing to not relocate because I really like Portland (even the rain). I recently moved to NW Portland, about one block from Forest Park, and I really love being able to walk out my front door and start hiking (or mountain biking) almost immediately.

Now, I’m not just looking for any old job; I’m looking for a Web development position, especially one where I’ll be able to use modern and innovative tools, techniques, and best practices—for example, Ruby on Rails or Django, AJAX, and RESTful architecture. I’m not entirely averse to working with PHP, but my preference is Python or Ruby.

I’ve also been studying up on Java technologies so I’ll have more options if necessary. After much study, I finally understand what Java EE is, what the various parts of a Java enterprise application are and how they fit together. I’ve also learned that there are even more Web frameworks for Java than there are for Python (although Struts 1.x seems to be the de facto standard).

There is more info in my resume, but I just put it up and it needs work. My bio may be of interest also. If you know of something, please let me know about it.

Ruby on Rails and Opinions on Opinionated Web Frameworks

I originally started this over on the byCycle blog [which is currently offline--3/20/08], but it doesn’t really belong there, so I moved it over here on 1/3/2007. It’s not finished, but I think it may contain some useful info, so here it is…

Introduction

In this post I’m going to discuss my first real foray into the world of Ruby and Ruby on Rails (AKA Rails). I’m also going to talk about how my initial experience with Ruby and Rails has differed from my recent and ongoing experience with Pylons, a similar-to-Rails Python framework.

Background

Recently, mostly by chance, I came across a job posting on craigslist by a local startup looking for a Ruby on Rails developer. I’m not actively looking for a job, but I guess I was “bored” or something and was curious what the jobs landscape in Portland is looking like these days.

A (long) while back when I was looking at CL more regularly, it seemed like all the jobs were Java or PHP related and required five years of experience (yes, I’m generalizing). Now I’m not gonna say I “hate” Java or PHP, but the end result is about the same. On the other hand, this job looks very interesting, and I’m even preparing a cover letter and resume for it.

Since getting into Python about two years ago, I’ve heard of Ruby and even tinkered with it some. And since we’re developing a Web application, I’ve definitely heard of Ruby on Rails. Several months back, I created a Rails project and poked around in it some (i.e., typed ‘rails project_name’ then ’./script/server’) but didn’t really do anything with it.

There seems to be a little strain between the Python and Ruby communities, especially on the Web framework front, but the consensus seems to be that the two languages are more similar than different. My recent experience has been with Python Web frameworks similar to Rails, especially Pylons.

From past experience learning new languages, and particularly because of their similarities, I don’t think I would have any trouble transitioning from Python/Pylons to Ruby/Rails. Just to make sure, though, I figured I should do at least a small project using Rails. I haven’t done anything with my personal site in a long time and it’s fairly simple, so I decided to give it a Rails makeover.

Initial Impressions

  • Ruby: +1
  • Wacky Interactive tutorial and book: +1 [Why’s]
  • Rails: +1
  • Rails support and community: +1
  • Opinionated frameworks: +1
  • RadRails Eclipse-based IDE: +1
  • Emacs as Rails IDE: -1
  • VIM (actually cream) as Rails IDE: -1

First Steps

One of the first things I did was to check out the official Ruby site. What I especially liked there was the interactive tutorial, which embeds a Ruby console in a Web page. Even non-programmers would be able to follow this, and I recommend giving it a try. If you’re a seasoned programmer, the tutorial is pretty lightweight, but it does serve as a good introduction to Ruby if you’ve never really done anything with it.

IDE

I’m using Ubuntu, and I first started working on the project in Emacs. Emacs is a good editor and is what I have historically used for all kinds of files, but I’m finding that it kind of sucks (at least for me) for this type of thing, even after installing all the whiz-bang Ruby/Rails modes and whatnot.

One thing I really like is an easy way to navigate all the project files. I like document tabs and tree views and that sort of thing. I tried various ways of getting those things in Emacs and VIM, but it just seems clunky, and doesn’t have all the pretty little icons and stuff.

Internet research turned up a few other contenders. A few people seem to be happy with JEdit and claim it can be set up to be very similar to TextMate on Mac OS X. I wouldn’t know because I haven’t used TextMate extensively and I haven’t installed JEdit yet (and I might not).

I already had Eclipse installed from an earlier attempt at using PyDev. I never used it much because it was too damn slow. Important: This time around I am using Sun’s JVM [now GPLed, w00t!] instead of the one that comes with Ubuntu, and this makes a huge difference: I’m actually able to use it!

So far, it does seem pretty rad indeed [with the Eclipse RadRails plugin]. One gotcha so far: it requires setting a host, port, and password in database.yml, even if you don’t need this from the command line. Something to do with ODBC or JDBC or whatever Eclipse/Java uses to connect to databases.

Database Issues

I don’t remember what I thought the issues were way back when. It turned out that the FreeBSD 6.1 jail (VPS) I was trying to deploy to had some issue with Postgres and semaphores and ports and other users and some such (yada yada), and Postgres would continuously barf (randomly, sometimes staying up for days, sometimes hours). The hosting company was no help, I couldn’t find much info via The Google, and it just wasn’t worth the trouble at the time, so I gave up and dumped the company.