IE and Absolute Positioning

Posted by Trey on October 29, 2006

There are some seriously messed up things with absolute positioning in IE 6. I struggled and struggled tonight trying to get a logo to sit in the top left part of the #wrapper div:

#logo { position: absolute; }
#wrapper { position: relative; }

The logo was just not there. I ended up putting it in one of the main content columns, and it showed up in the right place (luckily, it also works in other browsers as well that way).

I couldn’t find much, if anything, useful about this behavior. Why do I always have some trouble with absolute positioning? Why aren’t more people blogging about this? Absolute positioning is supposed to be so easy that it’s considered cheating.

RESTful form validation?

Posted by Trey on October 23, 2006

So I hear there’s not a straightforward way to do validation with a RESTful setup. Is that true?

If not, how do you do it?

Update (Oct 29, 2006): How about this:

in order to get the error messages ‘we have all grown to love’ back, all you need to do is take this code & throw it at the end of the function above:

rescue ActiveRecord::RecordInvalid

render :action => ‘new’

Found that here.

So you put that at the very end of your create or update action, and it puts everything back the way it used to be: lists all errors and adds <div class="fieldWithErrors"> around the field with errors.

Can someone explain to me why this is necessary? Something about the way that RESTful things pass information back and forth? Is this going to be fixed (back to the way it used to be) before Rails 1.2?

Most importantly, does doing this hurt any of the respond_to stuff?

Update x2 (Oct 29, 2006): … Ok it’s late and maybe I’m seeing things, but it looks like just putting <%= error_messages_for "model" %> in the view is making everything work. Jeez.

Using SQLite with Rails

Posted by Trey on October 22, 2006

After watching the RESTful Rails PeepCode presentation, I had to try using SQLite for development. That’s nice to not have to set up a database for every little thing you want to play with.

SQLite 3 is already installed on OS X. To get it to work with Rails:

$ sudo port install swig
$ sudo gem install sqlite3-ruby

That will bring up a prompt to choose a gem. Choose the highest version number that says (ruby) after it.

Then you can do things like this in your database.yml:

development:
  adapter: sqlite3
  database: db/development.sqlite3

Source: Rails wiki

Creating Avery label templates in InDesign

Posted by Trey on October 13, 2006

  • Find which label you want to use in Word
    • Tools > Labels > Options
  • Find the specs for that label
    • > Details
  • Create new document in InDesign
  • Set up number of columns, gutter (space between columns), and margins
  • Create text boxes for the individual labels
    • Drag an area using the text tool, then set the exact width, height, and position using the properties of that text area.
  • Duplicate text areas to fill the page in the proper places.

Basic CRUD using REST in Rails

Posted by Trey on October 11, 2006

First, get on Edge Rails. Easiest way:

rake rails:freeze:edge
rake rails:update

Then generate some new-school scaffolding:

script/generate scaffold_resource ModelName

This generates a migration template for you. Use that to fill in the details then run rake db:migrate.

In app/views/ModelName, you’ll have to add the details of your model to the different forms. Something like this:

<div><label>Name: <%= f.text_field :name %></label></div>
<div><label>Description: <%= f.text_area :description %></label></div>

I still haven’t figured out how to get things to actually work.

Update 21.10.2006: My problem in getting things to work was a matter of putting my RESTful routes information at the top of the config/routes.db file. Top == higher priority.

Sources

Continued here

OLs in IE

Posted by Trey on October 09, 2006

If you set an OL LI to have height: 1% (to trigger has-layout) in IE, the number won’t increment. Freaky.

Using Subversion to upgrade WordPress

Posted by Trey on October 08, 2006

Update (November 1, 2006): It really works. I’ve got all 3 of my blogs (one two three) now set up on SVN. The next step will to be when I add my customized themes to Subversion so all I ever have to do is go to the command line to do anything. No (s)FTP or anything. I imagine this will make switching servers really easy now.

Update (January 23, 2007): To upgrade to WordPress 2.1:

  1. Disable all plugins (take a screenshot first)
  2. Run this command:
svn switch http://svn.automattic.com/wordpress/branches/2.1/
  1. Go to your admin screen and update the database when prompted.
  2. Enable your plugins again.

Update (May 22, 2007): Just upgraded to version 2.2

Making a POST link in Rails

Posted by Trey on October 05, 2006

You know you shouldn’t be using GETs (URLs) for deleting things, right? Here’s how you do it in Rails:

<%= link_to "Destroy account", { :action => "destroy" }, :confirm => "Are you sure?", :post => true %>

(example is from the API docs)

:post => true! That’s awesome. Of course, it’s not unobtrusive, but maybe UJS could fix that.

Adding REL attribute to Rails link_to

Posted by Trey on October 05, 2006

<%= link_to 'Pumpkin', { :action => 'index', :controller => 'main' }, :rel => 'lightbox' %>

Source

Change the default folder for file_column to store images

Posted by Trey on October 02, 2006

Update 2006-12-31: I don’t think this is quite right. It keeps creating a folder in my Rails root as well as in public/. I think I might switch to acts_as_attachment anyway.

In your model, where you define the sizes and whatnot that you want, put:

file_column :database_column_name,
  :store_dir => 'path/you/want',
  :base_url => 'path/you/want',
  (the rest of your configuration)

So what you end up with is images going into rails_root/public/path/you/want/database_id_of_image/