Posts for: #Ruby on Rails

Rails: How to force plugins loading in 2.0

Sometimes a Rails plugin can be dependant from another one. Since plugins are loaded in alphabetic order, probably you need to load the third part plugin first.

The release 1.2.4 2.0PR introduces breaking changes for this mechanism.

I’m developing a plugin called ClickToGlobalize, that’s dependant on Globalize, here the code for plugin initialization:

# Force Globalize loading. if Rails::VERSION::STRING.match /^1\.2+/ load_plugin(File.join(RAILS_ROOT, 'vendor', 'plugins', 'globalize')) else Rails::Initializer.run { |config| config.plugins = [ :globalize ] } end
require 'click_to_globalize'

Explanation

Use the old mechanism if the current release is minor than the last release with it (1.2.3 1.2.4), else use the Rails::Initializer class.

[]

Rails To Italy 07 - Coding Challenge

Coding Challenge

The Rails To Italy conference has started a Coding Challenge. The topic will be “Your Favourite Thing” - create a small, interactive web application that is related to your favorite thing or activity*.

Prizes

Prizes are 1 iPhone or iPod touch + 2 iPod shuffle!

Deadline

Submission deadline is the 20th October 2007.

[Rails To Italy 07 - Coding Challenge]

[]

Ruby on Rails: Validate URL

Hi, just a snippet to validate an url with Ruby on Rails.

class WebSite /^((http|https):\/\/)*[a-z0-9_-]{1,}\.*[a-z0-9_-]{1,}\.[a-z]{2,4}\/*$/i
  def validate
    errors.add(:url, "unexistent") unless WebSite.existent_url?(:url)
  end

  def self.existent_url?(url)
    uri = URI.parse(url)
    http_conn = Net::HTTP.new(uri.host, uri.port)
    resp, data = http_conn.head("/" , nil)
    resp.code == "200"
  end
end
[]