Posts

Showing posts with the label rails

Grails, Groovy, & some other stuff

As the name suggests WebDevRadio is a web development podcast. I'm a big fan of this show. It always delivers an interesting perspective, and the discussions often relate to a technology I'm also exploring. In a recent episode, the host Michael Kimsal interviewed Jason Rudolph about Jason's new book Getting Started with Grails . I've written before about Ruby and Rails and using something like JRuby to leverage Java's stability and scalability in a production environment. Grails (and Groovy ) is an interesting alternative to the Rails/Ruby/JRuby I'd been thinking about. Like Ruby, Groovy is an interpreted language but with some constructs that make it easier for Java developers to transition over. Also, since it's written for the JVM, it gets all the Java maturity "for free" and naturally integrates with existing Java modules (No need for something like JRuby). Grails brings the Rails goodness to the Groovy platform... including a lot of ...

Back Riding Rails

Thankfully, I'm done working with Hibernate for a while and I'm back on Rails. Since I posted on FRail :include , it seems there has been a lot of plugin development to add this functionality. While all of these plugins help to address the problem, I'm having a hard time finding one to address my specific scenario. I think I've explained my situation before, but here it is again in a nutshell. The company I work for aggregates a lot of data. The goal of my application is to allow users to sift out the information they don't need, discovering nuggets of truly useful knowledge. The approach we're taking is to have users to start from something they're interested in, and use that object to find other objects with similar attributes and characteristics. What I really need from Rails is a robust way to join a lot of tables together and specify search criteria. I've decided to roll my own solution for now. What I'm developing in Rails will take in o...

FRail :include

I really like developing with Rails, but I've been frustrated the last few days by some things Rails should do quite easily, yet doesn't. I've already written here and here about some of my struggles with Rails :include clause. Here's one more... Let's say you have a has-and-belongs-to-many relationship. If you :include this relationship in a find query, Rails will automatically create the join clause including the lookup table! That's cool. Unfortunately, it looks as if only the :include clause provides this piece of functionality. Why isn't the same functionality provided via the :join clause or through a general purpose module? This doesn't make any sense to me! I'm working on a database application where I don't need to display a lot of data, but the data displayed is heavily filtered by it's connections to other information in the database. I need to join a lot of tables to perform the filtering operation and using :include ...

wRESTling with REST

I'm still struggling with the decision to create a REST or traditional web service. Over the weekend I started reading RESTful Web Services and I'm now thinking that a RESTful approach is very doable. Here are my thoughts: REST resources are inherently stateless and shareable. All the information needed to reconstruct the view of a resource exists in the URI. Although I listed this a a "pro" before reading the book, I'm more convinced of the benefits now. I had a concern about long query criteria in the URI, but I'm thinking of adopting the Ruby-like approach of referring to ids. The RESTful authors prefer a more human readable URI (as it is self documenting), but many of my filter criteria cannot be accessed through unique strings. I believe I was trying to do too much at the beginning (not keeping it simple). My object relationships are complex, with most objects linked to several related (non-subordinate) lists of objects. I wanted to have a sin...

Should I REST?

Now that the models are complete, I want to expose access to them as a web service. I'm thinking REST is the way to go. A RESTful approach seems simple. It appears to solve pesky "back button" problems and session timeout issues, but I have one big question: How to fit all the information I need into the URL? The application I'm working on has A LOT of data. The main objective of the application is to allow filtering of this data down to a useful, manageable set. It wouldn't be uncommon for a user to ask for something like: Give me everything connected to Item1, Item2 and Item3, Hide anything that has to do with Item4 or Item5 In addition, give me anything that mentions Items 6, 7, or 8 and is new to the system in the past month. To put all this information in the URL is a scary proposition. In it's previous life as a Java web application, all this search criteria was built incrementally and stored in a user's session. Since the client ...

Rails Progress

All my models are implemented in Rails and I wanted to give a quick update on how things are going. For now, I'm been using the rails views and controllers to test my code (automated tests coming soon). This has worked out great for me. Since my application only allows users to view and filter database records, I don't have a lot of validation checks, but I wanted to get a feel for the performance of pages need to display a lot of data from various tables. One page I tested performs 35 queries (including all the counts and show field commands) and takes about 5 seconds using the Webrick server (from NetBeans so I believe JRuby is being used). The development log lists the time spent in the database as less than 1 second. I'm sure performance could be better, but this is a big improvement over what we had before and the database I'm using contains more records. I'm still noticing that when you ":include" more than one model in a "find" comman...

Good Migrations

I was out last week, but finally got my schema in a Rails friendly format and the scaffolding utility is working great! I thought I'd hit on some of the pain points I experienced during this process and how I worked through them. MySql stinks when you need to change the schema of a database containing data. To make things easy, I've been working with an empty database and using the MySQL administrator to capture the SQL. The plan was to run this SQL against existing databases to upgrade them. This process doesn't work like I'd hoped. For some columns, the SQL query fails when I try to change a column name (like changing the primary key name to the Rails default 'id'). There are no foreign key constraints on this field and it does not fail on every table where the column name must change. I can't figure out why MySQL bombs on these specific statements. Maybe it's because these table have large row counts (~1M rows)??? Luckily, I won't be creat...

More Rails Progress

I've been playing with Rails over the past few days and want to quickly express my experience so far. Creating joins, lookup tables, tuning, grouping, sorting, and setting limits are all easy. You can do something like: Actor.sum(:appearances, :joins => "INNER JOIN appearances_show_lookup asl ON asl.appearances_id = appearances.appearances_id", :group=>'asl.appearances_id', :order=>'sum(appearances) DESC', :limit=>10) which translates into SELECT m.appearances_id, sum(appearances) FROM appearances m INNER JOIN appearances_show_lookup md ON md.appearances_id=m.appearances_id GROUP BY m.appearances_id ORDER BY sum(appearances) DESC LIMIT 10; or... Actor.find(:all,include=>:appearances_type, :conditions=>"appearances_type.name='guest'", :limit=>10) to SELECT * FROM appearances LEFT OUTER JOIN appearances_type ON appearances_type.appearances_type_id = appearances.appearances_type_id WHERE...

Rails Progress

I picked up a copy of Rails for Java Developers by Stuart Halloway and Justin Gehtland and am playing around more with Rails. The book is really good, but I really need a migration guide from Hibernate to Rails (or an existing web application to Rails). I'm looking for more information on creating Rails models that can be accessed through a complex set of filters and associations. The things I need to know are: How to create something like a 8 table Rails join? How best to represent lookup tables? What options are available to tune the queries? Can I capture the Rails query before it's sent to the DB for debugging (outside the MySQL log)? How do I specify things like limit, paging, group by, sum, distinct, etc? I'm going to reread the ActiveRecord chapter of this book again. I also have a copy of Agile Web Development with Rails on the way. Many articles I'm finding on the Internet draw the same conclusions - if your schema and object dependencies ar...

JRuby

The database cleanup is finally complete! Now I need to rewrite our web app's data access code. When we first created the database layer, we used the Hibernate framework. Since then Hibernate3 has been released and an upgrade is scheduled as part of this work. We did have some pain points with Hibernate, however. For instance, when I started evaluating our DB code, I noticed some DB queries that we don't explicitly create. Whether these were the result of a poor object-relational model, lazy instantiation, or some other Hibernate functionality is unknown at this time. I've found Hibernate (or at least how we're using Hibernate) complicated to debug. I'm going to take some time and look at Ruby and Rails as an alternative. I've mentioned before that I've wanted to learn Ruby for a while and this seems like a good excuse. There is a Ruby library for Java called JRuby . The plan is to learn the JRuby Rails extensions and find out the effort to incor...