AJAX Spellchecker

Posted by sbecker Thu, 25 Aug 2005 23:39:00 GMT

How to build an AJAX spellchecker with Ruby on Rails

Word. That is pretty aweseome.

Edit: hahaha, see above. i just went back and read what i posted. oh the irony…

RoR Grid Control Part II 6

Posted by sbecker Wed, 03 Aug 2005 08:52:00 GMT

My reusable “grid control” with paging and filtering is almost finished. I made some changes to the syntax, and I converted the whole thing to a component, so it can simply be dropped in the components directory of a rails app and used as is.

Defining the columns is very DRY, the minimum thing you have to specify for each column is a title. From this the component will guess the actual database column to be the same (with spaces converted to underscores). If your database column name is different, you can specify that.

I also added some display format options, including “email”, “website” and “money” and “date”. These will make the columns look and behave as you would expect.

Here’s what the code to call it looks like now:

  def my_controller_method
    grid_html = render_component_as_string(:controller => 'controls/grid', :action => 'grid',
      :params => {
        :model => Product,
        :obj => params[:obj],
        :columns => [
          { :title => "Category",
             :db_column => "category_name",
             :filter_type => :select,
             :filter_column => "category_id",
             :filter_options => Category.find(:all, :order => "name ASC").collect {|c| [ c.name, c.id ] }
          },
          { :title => "Name" },
          { :title => "Published",
             :filter_type => :select,
             :filter_options => Product.published_options
          },
          { :title => "Featured",
             :filter_type => :select,
             :filter_options => Product.featured_options
          },
          { :title => "Retail", 
             :db_column => "retail_price", 
             :format => :money, 
             :filter => :false 
          },
          { :title => "Stock", 
             :db_column => "in_stock", 
             :filter => :false }
        ],
        :joins => ["LEFT OUTER JOIN categories ON products.category_id = categories.id"],
        :alias_columns => [["categories.name", "category_name"]],
        :order_by => "category_name, products.name",
        :per_page => 25
      })
    render :text => grid_html, :layout => true
  end

Once I get everything reasonably ironed out and add a few more things like sorting, I plan to open source this code…

Again, here is what mine looks like. This could easily be customized to look any way you want, by simply modifying the view rhtml file:

lighttpd / apache / textdrive speed up!

Posted by sbecker Sat, 30 Jul 2005 02:01:55 GMT

My websites running on textdrive were running really slow, which was frustrating since I’ve heard all the talk about how lighttpd is supposed to be fast fast fast. I was starting to think it was because my sites are on a shared server with many other websites. To my relief, it wasn’t that at all. After digging around on their forums, I discovered the issue!

To quote user ‘jmoses’:

“The slowness is caused by the Apache proxying. It takes apache forever to lookup the domain name to forward to.

If you change your ProxyPass and ProxyPassReverse from http://<hostname>:<port> to http://localhost:<port> you should see a dramatic speedup. I went from ~5-8s a request, to <1s."

Well, I just made the change, and bam, my sites are way faster.

See the whole thread.

They really need to change this on the textdrive manuals site.

MySpace sold to FOX 2

Posted by sbecker Tue, 19 Jul 2005 02:52:00 GMT

Wow. News Corp (owners of FOX) have agreed to purchase Intermix Media (owners of MySpace) for $580 million. Any web developer including myself could have written that website. It’s really not even that great! It could be so much better.

Really need to start thinking about what “next big thing” to create.

Ruby on Rails Data Grid Control 8

Posted by sbecker Sun, 10 Jul 2005 11:38:00 GMT

As far as I can tell, Ruby on Rails doesn’t have a built in control for displaying tabular data in a grid. Not a rich one anyway, with paging/sorting/filtering capability built-in. I plan on attempting to create one. I’m actually almost there. I’m doing this instead of getting my actual projects done. :)

All parameters should have defaults to do the standard thing, with ability to further customize if so desired. Convention over configuration and all that. It should be able to do sorting/paging on columns from associated tables as well. Here’s the proposed syntax for how this might be called in a controller:

a simple example
class AgreementsController < ApplicationController

  def list_simple
    grid_view(Agreement,
      :columns => ['title', 'active', 'amount', 'frequency']
    )
  end

end

a more complex example:

class AgreementsController < ApplicationController

  def list_complex
    grid_view(
      Agreement,
      :columns => [
        "Status",
        "Company Name" => {
          :dbcolumn => "company_name",
          :filter => true
        },
        "Category" => {
          :dbcolumn => "agreement.category_id",
          :filter => true,
          :filter_type => :select,
          :filter_options => Category.find_all.collect {|c| [ c.name, c.id ] }
        },
        "Active" => {
          :dbcolumn => "agreement.active",
          :filter => true,
          :filter_type => :select,
          :filter_options => [["Yes", 1], ["No", 0]]
        }
      ],
      :joins => ["LEFT OUTER JOIN categories ON agreements.category_id = categories.id",
                 "LEFT OUTER JOIN companies ON agreements.company_id = company.id"]
      :alias_columns => [["companies.name", "company_name"],["categories.name", "category_name"]],
      :order_by => "category_name, products.name",
      :per_page => 25
    )
  end

end

The grid_view method will be at the application level, so you can call it from any controller. The presentation (view) will live in one /shared/_grid_view.rhtml partial file and be 100% customizable. And because of that, it doesn’t even have to be a table or look like a grid! The MVC pattern of rails allows this, and would make this far superior and easier to customize than say – the ASP.NET data grid control, in my opinion. Here’s one possible way such a beast might look like:

Prelude

Posted by sbecker Tue, 21 Jun 2005 23:54:00 GMT

Just a quick obligatory introduction – I’m Scott Becker, a web designer, developer and entrepreneur by day, musician and party animal by night, living in good old Tampa Florida in the US of A. This is intended to be my tech blog, where I comment on technology and generally get my geek on. On to more useful information…

Older posts: 1 ... 4 5 6