October 2007

Strip HTML in any string in Ruby

A little code snippet to let you remove HTML from any string in Ruby:
[source:ruby]
class String

# remove all HTML tags from the source string
def strip_html
self.gsub(/< \/?[^>]*>/, "")
end

end
[/source]
Then to run the code just do this:
[source:ruby]
blurb_html = "

Thanks for visiting our site.

"
blurb_text = blurb_html.strip_html
[/source]

Tags: 

Making a form reset button in Rails

Rails doesn't have reset_tag to automatically make a form reset button, instead you have to take a slightly different route. To make a form reset button in Rails you simply do this:
[source:ruby]
< %= submit_tag("Start Over", { :name => 'reset', :id => 'reset_button', :type => "reset" }) %>
[/source]
which will create the following:
[source:html]

[/source]

Tags: 

(not going to finish) Production web serving with Cygwin - PHP, Ruby on Rails & ColdFusion

Note: I'm not going to finish this article as ultimately I ran into problems with Cygwin so migrated to running all Windows-native tasks. Still, in its raw state someone might find some use out of it.

Tags: 

Two most important things for PHP development

After having developed in PHP for many years I've realized that the two most important things a developer can do are:

Those two simple changes will greatly help reduce problems in your code. Now to just get all OSS developers to do the same...

Tags: 

Insanely easy tabbed web pages with Prototype

I came across this today when trying to find an easier way to present a six-part form in a Rails project - a tabbed interface system built upon Prototype (an integral part of Rails). Called Control.Tabs it makes tabbed interfaces a synch to do: simply add an unordered list containing links to the blocks containing your to-be-tabbed content, and add a line of JavaScript to start the ball rolling - that's it!

Tags: 

Reminder - rails forms with file uploads

Just a quick reminder for myself: if you're doing a form that is uploading files, remember to add :multipart => true to the form tag, e.g.:
[source:ruby]
< % form_for(:product, :url => products_path(@product), :html => {:multipart => true, :method => :put }) do |f| %>

< %= f.file_field :photo %>

< % end %>
[/source]

Tags: 

Bug in Safari 3 beta: hidden file fields don't get submitted

I've just wasted several hours due to what turned out to be a bug in the current Safari 3 beta (on OSX Tiger). If you have a form with some DIVs set to display:none;, any file fields that are in the hidden DIVs do not get submitted along with the rest of the data, whereas text fields are submitted. This inconsistency does not exist in Firefox 2 - it submits all of the available fields. Bad Safari, bad!

Tags: 

Laptops are complicated wee beasties!

Last night when I went to bed my new (to me anyway) Powerbook G4 was working fine. This morning when I got up it was severely misbehaving - there was 9.5gb of RAM in use and nothing was responding. I started shutting everything down and at one point tried to turn off the local ColdFusion 8 server using sudo, only to have an error that my account wasn't in the sudoers list; given that my account was an administrator, this was not good. I left it to continue rebooting but when I got back, a half hour later, it had pretty much frozen up trying to load a few starter apps. This, along with the noise coming from the drive, told me what I already knew - the drive was dead.

Tags: