Getting feet wet with Rails

I finally made time to install Rails, planning on taking it for a test drive by making a Ruby on Rails version of the lightweight asset manager database we put together to store assets for Pachyderm.

Initially, I guess my install of Rails didn’t have MySQL support (why on earth wouldn’t that be included right out of the box?), and it kept barfing when it tried to connect. So, I installed or updated my MySQL kit via gem install mysql and it was able to build a simple scaffolded app to let me create a single record via the dynamically generated interface. That was pretty cool – automatically figuring out which widgets should be used, etc… Very WebObjects D2W.

But, it barfed on a field name in the table – it didn’t like “type” at all. So, I renamed that field to “assettype” in my local copy of the database. Now I can create a record.

But, using the “list” action gives me an error:

ArgumentError in Asset#list

Showing /usr/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/templates/scaffolds/list.rhtml where line #13 raised:

too few arguments.

Extracted source (around line #13):

10: <% for entry in instance_variable_get("@#{@scaffold_plural_name}") %>
11:   
12:   <% for column in @scaffold_class.content_columns %>
13:     <%= entry.send(column.name) %>
14:   <% end %>
15:     <%= link_to "Show", :action => "show#{@scaffold_suffix}", :id => entry %>
16:     <%= link_to "Edit", :action => "edit#{@scaffold_suffix}", :id => entry %>

So, I’m kinda stuck. Rails seems REALLY promising, and everything I’ve heard/read about it makes me want to do a lot of stuff in it. I love the develop/test/deploy distinctions built in from square one. I love the unit testing built in. I love Ruby (but haven’t really used it too much – it seems reminiscent of Lingo, but that’s because Lingo is another Smalltalk derivative, via Hypertalk). Also, Rails just celebrated its first birthday, and was apparently received extremely well at OSCon.

But, the magical “it will build a wonderful app with no code” hype fell a bit short for me, at least initially…

Update: Turns out it was choking on a field named “format” in my “assets” table. Renamed the field to “dc_format” and it appears to be happy… Now that the Rails setup seems to work, and I’ve debugged the database schema conflict, it’s actually very cool how it builds the dynamic app to manage records! Full “view”, “edit”, “add”, “list” and “delete” actions, with a totally usable (but rough) UI. Now to dig in to see how to customize the layout of the dynamic app…

So, for Google’s sake, Rails doesn’t like these field names for tables: type, format – there may be others, but these are the ones that tripped me up so far…

Also, it’s a bit odd that the default scaffolding app doesn’t appear to provide a search function… I can list all records and page through them, but can’t do a quick search? WebObjects D2W does that right out of the box, even generating “advanced search” forms at will. Looks like Rails has a plugin gem to do this (Search Generator Gem), but it’s apparently a bit rough, and not included with Rails as a stock feature.

I finally made time to install Rails, planning on taking it for a test drive by making a Ruby on Rails version of the lightweight asset manager database we put together to store assets for Pachyderm.

Initially, I guess my install of Rails didn’t have MySQL support (why on earth wouldn’t that be included right out of the box?), and it kept barfing when it tried to connect. So, I installed or updated my MySQL kit via gem install mysql and it was able to build a simple scaffolded app to let me create a single record via the dynamically generated interface. That was pretty cool – automatically figuring out which widgets should be used, etc… Very WebObjects D2W.

But, it barfed on a field name in the table – it didn’t like “type” at all. So, I renamed that field to “assettype” in my local copy of the database. Now I can create a record.

But, using the “list” action gives me an error:

ArgumentError in Asset#list

Showing /usr/lib/ruby/gems/1.8/gems/actionpack-1.9.1/lib/action_controller/templates/scaffolds/list.rhtml where line #13 raised:

too few arguments.

Extracted source (around line #13):

10: <% for entry in instance_variable_get("@#{@scaffold_plural_name}") %>
11:   
12:   <% for column in @scaffold_class.content_columns %>
13:     <%= entry.send(column.name) %>
14:   <% end %>
15:     <%= link_to "Show", :action => "show#{@scaffold_suffix}", :id => entry %>
16:     <%= link_to "Edit", :action => "edit#{@scaffold_suffix}", :id => entry %>

So, I’m kinda stuck. Rails seems REALLY promising, and everything I’ve heard/read about it makes me want to do a lot of stuff in it. I love the develop/test/deploy distinctions built in from square one. I love the unit testing built in. I love Ruby (but haven’t really used it too much – it seems reminiscent of Lingo, but that’s because Lingo is another Smalltalk derivative, via Hypertalk). Also, Rails just celebrated its first birthday, and was apparently received extremely well at OSCon.

But, the magical “it will build a wonderful app with no code” hype fell a bit short for me, at least initially…

Update: Turns out it was choking on a field named “format” in my “assets” table. Renamed the field to “dc_format” and it appears to be happy… Now that the Rails setup seems to work, and I’ve debugged the database schema conflict, it’s actually very cool how it builds the dynamic app to manage records! Full “view”, “edit”, “add”, “list” and “delete” actions, with a totally usable (but rough) UI. Now to dig in to see how to customize the layout of the dynamic app…

So, for Google’s sake, Rails doesn’t like these field names for tables: type, format – there may be others, but these are the ones that tripped me up so far…

Also, it’s a bit odd that the default scaffolding app doesn’t appear to provide a search function… I can list all records and page through them, but can’t do a quick search? WebObjects D2W does that right out of the box, even generating “advanced search” forms at will. Looks like Rails has a plugin gem to do this (Search Generator Gem), but it’s apparently a bit rough, and not included with Rails as a stock feature.

13 thoughts on “Getting feet wet with Rails”

  1. I have no idea what is causing your error but I am a WO programmer that is re-writing two apps in RoR.

    So far I’m really loving it.

    I think a lot of it is loving Ruby over the shackles of Java-dom but overall RoR feels more lightweight than WO.

    Not having a compile cycle is very nice… And not having to use WOBuilder is very nice. I don’t explain to my customers why the form output from WO elements isn’t XHTML!

  2. Hunter, it’s more than likely a result of some funkiness in my database schema – perhaps some more unsanctioned fieldnames or data types. I’ll try a simpler first app to see how that works. Also, my database has “auto-increment” disabled on the PK, because it’s also used by WebObjects, and EOF likes to do its silly EO_PK_TABLE nonsense rather than behaving like a regular MySQL client.

  3. …yeah, the ‘with no code’ is with the caveat that you follow all of the assumed conventions. Any deviance requires configuration. ‘no code’ is optimistic, but still, even if you have to code, Ruby ensures you’re not talking about a lot of code.

  4. Yeah. If I’d have RTFM, I may have stumbled across a list of “don’t use these as field names” gotchas – still haven’t seen one though…

    But still, that was a pretty simple thing to debug.

    Really surprised that “search” isn’t part of the default scaffolding though. What good is a CRUD app without search?

  5. Um. woah. Search Generator keeps its own search index, outside of MySQL, in a flat text file. And it needs to be updated to let it find stuff. *cough*hack*ahem* While it does work, and I suppose it would be handy for cross-database and non-database searches, I’ll take a closer look at the code you linked to, Josh 🙂

  6. I’d be interested in seeing a comparison of WebObjects and Ruby on Rails once you’re a little more familiar with RoR, as I’m interested in learning one or the other (time constraints). Everything I’ve read about WebObjects makes it sounds really incredible, but there’s also a lot of buzz for RoR, so to hear from someone who has a better grasp of both breaking things down would be very much appreciated.

  7. I’m planning on writing something after I finish porting my Las Vegas tourism site from WO to Rails.

    WO is incredible. The problem is that Apple is letting it languish.

    Honestly, a lot of the things people like in Rails are in WO but no one has ever heard of WO…

    Rails benefits from being Open Source and thus progressing very quickly where WO 5.3++ has the potential of being OSXS only, which is a bit scary to folks like me.

  8. Search generator is a bit like Java Lucene, yes?

    D’Arcy – how do you usually do full-text search in WO apps? I’ve been using Lucene, which has an outside index.

    I believe there are Rails tools to use MySQL’s full text indexing as well.

  9. Bob: My initial reaction was something like “this is cool, but WebObjects and D2W has done this (and more) for a long long time now”. I do _really_ like the interpreted (rather than compiled) nature of the app, making rapid turnaround nice. I also _really_ like that it’s open source, and the terms of licensing can’t be pulled out from under me.

    Hunter: Search Generator does seem quite Lucene-like. For my WO apps, I implement more fine-grained searching – Fetch Specs mapping queries to important tables and fields. Not everything in the database should be searchable via a simple search interface, so that makes sense. D2W’s generated search forms are pretty cool at that, too.

    I haven’t really looked too far for searching in Rails – I would assume it’s pretty simple to get going, since it’s a very basic function of any app. I’ll take a deeper look when I get some time…

  10. Thanks for posting the update – I was getting the same error on my list view, so I Googled on the message and found the page. My problem also was a column named “format”.

  11. Ben, glad it was helpful. I was really surprised to not find more documentation online about “forbidden” field names in Rails. Seems like a rather important bit of info. At least in WebObjects, EOModeler.app will throw warnings if you try to model a table with funky field names.

Comments are closed.