Archives for Oct 2005

Is your web application rude?

When working on the computer, there’s nothing I hate more than my applications being rude to me. For instance, some web pages with forms to fill out will conveniently select the first form field for you.

That’s nice, unless it happens to be a slow loading page, and it decides to select the first field by the time you’re halfway through filling it out. Cameron Adams has provided a nifty script that actually checks and only selects the initial field if no fields have been filled out. This should be in every web developer’s toolbox.

0 comments | posted 26 Oct 15:51

Introducing acts_as_authenticated

Someone asked about it, so I’m finally posting the code for acts_as_authentication, my replacement for the various login generators. Why bother?

  • Most of the current login generators are old, still holding on to find_first calls.
  • With the exception of the original Login Generator, they are usually pretty heavy. Most of the times my app does not need internationalization or roles.
  • Encryption is set to sha1 usually.

This is mostly a reworking of Tobi’s Login Generator, implemented as plugins. We’re going for modular plugins that build on each other, not one all encompassing module that handles everything.

Much hacking and discussion ensued at RubyConf, though we mainly got the user model hashed out. I wrote the filter stuff waiting for my delayed plane trip home. But, you’ll notice the major part hasn’t even been touched yet: controllers.

I also borked my install of Collaboa, so all you get are subversion links:

acts_as_authenticated and authenticated_system.

0 comments | posted 24 Oct 19:23

more on WYSIWYG editors

I tried TinyMCE, and got it configured the way I like. However, I had some serious issues with IE6 and flaky textareas. I initially thought it was Prototype being rude (overwriting core javascript functions), but Sam said that was not the case as of v0.4.

Anyways, I ditched TinyMCE and just went with WidgEditor. Ten minutes from download and I had it fully integrated into Cloudnine, my Ruby on Rails publishing framework.

Plea to browser developers: please make this kind of thing integrated. We spend too much time in a browser window these days, not to have a decent writing environment.

Back to the trenches…

Update: I did some checking, and it looks like Safari support may be on the way. I have no clue how long it takes for a webkit nightly to make it onto Tiger desktops around the world, but this is encouraging.

0 comments | posted 19 Oct 08:29

changing your ActionController template_root per request

Normally, you change your template root with a class variable:

class MyController < ActionController::Base
  self.template_root = File.join(RAILS_ENV, 'app', 'views')
end

The publishing framework can use different view paths depending on which domain is being accessed. So without thinking, I try:

class MyController < ActionController::Base
  before_filter { |c| c.template_root = my_new_template_root }
end

The problem, however, is the the controller sets up the intial ActionView classes before calling the filters.

class MyController < ActionController::Base
  before_filter :set_site_template_root
  def set_site_template_root
    self.class.template_root = File.join(RAILS_ROOT, 'app', 'views', current_site.domain)
    @template.base_path = template_root
  end
end

All good, except the layout doesn’t show up…

0 comments | posted 11 Oct 15:09

Using the administration toolkit

Update: I’ve updated some of the directions to use edge rails and plugins.

Here’s a rapid-fire tutorial because some folks have been curious with the administration toolkit. This is assuming you’re running on Rails edge with the new plugin support. After creating the app directory, be sure to add vendor/rails of course:

ruby path/to/edgerails/railties/bin/rails my_app
rake freeze_edge
./script/plugin install http://svn.digett.com/svn/projects/administration

Set up your database.yml:

development:
  adapter: sqlite
  dbfile: db/dev.db
Create a model and a controller:

class Post < ActiveRecord::Base
end

class PostsController < ApplicationController
  admin_for :post do |admin|
    admin.list_view do |list|
      list.column :title
      list.column :content
      list.search :title
    end

    admin.form_view do |form|
      form.field :title
      form.field :content, :text_area
    end

    admin.confirm_delete_with :title
  end
end

Now, let’s create your database:

ActiveRecord::Base.connection.create_table :posts do |t|
  t.column :title, :string
  t.column :content, :string
  t.column :created_at, :datetime
end

Now, start your app and go to http://localhost:3000/posts. See anything?

0 comments | posted 10 Oct 10:07

choosing a rich text editor

I’m working on a project that needs a WYSIWYG editor, so I’ve been investigating several of them. TinyMCE worked well, but I have a beef with its configuration. It seems flexible enough, but I don’t have a desire to write my own plugin. I simple just want to add/remove buttons as I please.

I’ve used HTMLArea in the past, and found it to be pretty decent. It’s the only one I know that comes with a free cross-platform spell checking component as well. However, the project seems stagnant. The final killing blow is that the prototype library interferes with it. Maybe I can dig in there and figure out why, but I don’t quite feel like it right now. That’s a shame, because it’s simple to configure and works well.

I’ve personally never liked actually using any of these editors, as they all seem a bit dodgy to me. However, there are still people that can’t grok simple formatting symbols. They don’t know what RSS is, or care about your blogs. They just want to write copy for their website. It just seems natural that the browser should have a decent writing environment to accomodate that.

Web services are an option, but I’d still prefer to have something that doesn’t require an installation. Also, Jeremy briefly talks about using RailsFS to manage your document workflow. Hmm.

0 comments | posted 05 Oct 13:27