Phusion Passenger (a.k.a. mod_rails for Apache) Preview
Riding Rails: mod_rails is on the way
Tech Tidbits - Ruby, Ruby On Rails, Merb, .Net, Javascript, jQuery, Ajax, CSS...and other random bits and pieces.
Saturday, March 29, 2008
Sunday, March 23, 2008
Ruby on Rails - Using External Asset Hosts
Rails uses the "public" directory on the current host as the default location for static assets (images, CSS, Javascript, etc). Setting up your Rails app to use an external assets server is as simple as adding a single line to a configuration file.
Add the following line to your config/environment.rb file:
It's also possible to set a single environment to use an external asset host:
Add the following line to config/environments/production.rb (the most likely spot - this line should already be in this file, but commented out):
Now this line in my layout
will translate to http://assets.yourdomain.com/stylesheets/scaffold/base.css
Additional information on setting up multiple asset hosts can be found at:
http://api.rubyonrails.com/classes/ActionView/Helpers/AssetTagHelper.html
Add the following line to your config/environment.rb file:
ActionController::Base.asset_host = 'http://assets.yourdomain.com'
It's also possible to set a single environment to use an external asset host:
Add the following line to config/environments/production.rb (the most likely spot - this line should already be in this file, but commented out):
config.action_controller.asset_host = 'http://assets.yourdomain.com'
Now this line in my layout
<%= stylesheet_link_tag 'scaffold/base' %>
will translate to http://assets.yourdomain.com/stylesheets/scaffold/base.css
Additional information on setting up multiple asset hosts can be found at:
http://api.rubyonrails.com/classes/ActionView/Helpers/AssetTagHelper.html
Wednesday, March 12, 2008
Ruby Gem - Highline
I was looking for a way to prompt a user for input on the console and ran across the RubyGem HighLine. It does a lot more than this, but here's how to capture STDIN from the console:
Here's the output on the console:
Get it here:
HighLine
or simply install the gem the normal way:
$ sudo gem install highline
#!/usr/local/bin/ruby
require 'rubygems'
require 'highline/import'
username = ask("Enter your username: ") { |q| q.echo = true }
password = ask("Enter your password: ") { |q| q.echo = "*" }
Here's the output on the console:
$ ruby highline.rb
Enter your username: doug
Enter your password: ******
Get it here:
HighLine
or simply install the gem the normal way:
$ sudo gem install highline
Installing Ruby without openssl
When installing Ruby on an old machine, I got this error:
Other than installing openssl, which wasn't option, install ruby without openssl:
ruby make[1]: *** [ossl_ssl.o] Error 1
Other than installing openssl, which wasn't option, install ruby without openssl:
$ ./configure prefix=/home/doug/bin/ruby --without-openssl
Monday, March 10, 2008
Javascript - insertAfter(), formatCurrency, DOM Scripting
insertAfter()
formatCurrency()
DOM scripting - create text node with value of
function insertAfter(newElement,targetElement) {
var parent = targetElement.parentNode;
if (parent.lastChild == targetElement) {
parent.appendChild(newElement);
} else {
parent.insertBefore(newElement,targetElement.nextSibling);
}
}
formatCurrency()
function formatCurrency(amount) {
var i = parseFloat(amount);
if(isNaN(i)) { i = 0.00; }
var minus = '';
if(i < 0) { minus = '-'; }
i = Math.abs(i);
i = parseInt((i + .005) * 100);
i = i / 100;
s = new String(i);
if(s.indexOf('.') < 0) { s += '.00'; }
if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
s = minus + s;
return s;
}
DOM scripting - create text node with value of
var textEl = document.createTextNode('\u00a0');
Accordion Effects with Scriptaculous
I had a couple recent projects that required an accordion effect. I normally use jQuery, but found a couple nice Prototype/Scriptaculous accordions (one is for a Rails project, so we're already using Scriptaculous).
stickman labs
grf-design
Note - The stickman labs accordion doesn't appear to work with the latest Prototype (1.6.1). I'm using the combined js file from the stickman site.
stickman labs
grf-design
Note - The stickman labs accordion doesn't appear to work with the latest Prototype (1.6.1). I'm using the combined js file from the stickman site.
Labels:
accordion,
javascript,
prototype,
scriptaculous
Subscribe to:
Posts (Atom)
About Me
- Doug Sparling
- Developer (Ruby on Rails, iOS), musician/composer, Buddhist, HSP, Vegan, Aspie.
Labels
- .NET (8)
- accordion (1)
- ActiveRecord (1)
- ajax (2)
- APT (1)
- apt-get (1)
- ASP (1)
- ASP.NET .NET (5)
- Audio (1)
- aws (1)
- Bash (1)
- bdd (1)
- C# (1)
- cache_fu (1)
- caching (1)
- DocBook (1)
- DOM (1)
- Eclipse (1)
- Excel (1)
- Firefox (1)
- gem (5)
- Gems (5)
- git (1)
- GridView (2)
- Hibernate (1)
- iBATIS (1)
- Java (9)
- javascript (9)
- javascript css (1)
- jQuery (4)
- jsspec (1)
- mdb2 (2)
- Merb (2)
- mongrel (2)
- mp3 (2)
- Music (2)
- MySQL (2)
- nginx (1)
- openssl (1)
- osx (3)
- pdocast (1)
- pear (2)
- Perl (7)
- php (5)
- plugin (2)
- podcast (1)
- prototype (1)
- REST (1)
- RMagick MacOSX (1)
- rspec (1)
- ruby (14)
- ruby on rails (21)
- RubyGems Merb (1)
- s3 (1)
- screencasts (1)
- scriptaculous (1)
- scriptrunner ruby rails erlang (1)
- Sortable (1)
- subversion (1)
- testing (1)
- testing erlang tsung (1)
- tomcat (1)
- ubuntu (2)
- WebSphere (1)
- will_paginate (1)