Archive for the ‘rails’ Category
rails template
Usage $ rails app_name -m ./ahabman_template.rb
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/robots.txt"
run "rm -f public/javascripts/*"
gem ‘ruby-openid’, :lib => ‘openid’
rake("gems:install", :sudo => true)
plugin "kamui_restful_authentication", :git => ‘git://github.com/kamui/restful-authentication.git’
plugin ‘exception_notifier’, :git => ‘git://github.com/rails/exception_notification.git’
plugin ‘open_id_authentication’, :git => ‘git://github.com/rails/open_id_authentication.git’
#plugin ‘asset_packager’, :git => ‘http://synthesis.sbecker.net/pages/asset_packager’
plugin ‘role_requirement’, :git => ‘git://github.com/timcharper/role_requirement.git’
#plugin ‘acts_as_taggable_redux’, :git => ‘http://github.com/geemus/acts_as_taggable_redux/tree/master’
#plugin ‘restful-authentication’, :git => ‘git://github.com/technoweenie/restful-authentication.git’
generate("authenticated user sessions –include-activation [...]
ruby on rails - has and belongs to many view plugin
So I’ll never have to write another has_and_belongs_to_many view again, here’s a plugin that dynamically makes 2 <ul> lists which you drag and drop both ways to manage the association.
http://svn.ahabman.com/public/many_to_many_view/
From the readme:
Assumming you have an @project var and you want to associate people with it.
<div id=”m2m_container”>
<%= render :partial => “shared/m2m”, :locals => {
:thing => @project,
:association [...]
You can’t use class variables in rails.
You can’t use class variables in rails. Unless you’d like to develop in production mode (specifically with config.cache_classes = true). In development mode all classes are reloaded on each request, which clears all class variables.
I had the perfect place to use them - while running a mass synchronization, and needing to store the timestamp (I [...]
ruby csv to structured hash
I had a csv like this:
object
color
flavor
shape
apple
red
sweet
round
banana
yellow
sweet
long
lemon
yellow
sour
round
and I wanted a ruby hash structured like this:
{
‘apple’=> { ‘color’=>’red’, ‘flavor’=>’sweet’, ’shape’=>’round’},
‘banana’=> { ‘color’=>’yellow’, ‘flavor’=>’sweet’, ’shape’=>’long’},
‘lemon’=> { ‘color’=>’yellow’, ‘flavor’=>’sour’, ’shape’=>’round’}
}
So I wrote this, which does the job:
require "faster_csv"
def csv_to_structured_hash
arr_of_arrs = FasterCSV.read( ‘your.csv’ )
stuff = {}
header = arr_of_arrs.shift
arr_of_arrs.each_with_index do |row, i|
thing = { row[0] => {} }
header.each_with_index do |col, header_index|
thing[ [...]
Ruby conversion module
This is a ruby module useful for conversions dealing with length, weight, torque.
module Convert
def Convert.number_with_precision(number, precision=2)
“%01.#{precision}f” % number
rescue
number
end
def Convert.mm_to_in(mm, precision=2)
number_with_precision(mm * 0.03937, precision)
end
def Convert.in_to_mm(inches, precision=2)
number_with_precision(inches / 0.03937 , precision)
end
def Convert.feet_to_meters(f, precision=2)
number_with_precision( f * 0.3048, precision)
end
def Convert.meters_to_inches(m, precision=2)
number_with_precision( m * [...]
Rails redirect_to :back in Internet Explorer
Today I realized that the rails command redirect_to :back does not work in Internet Explorer because redirect_to :back depends on the HTTP_REFERER http header, which IE does not send. I was capturing an onclick event with jQuery and was able to sending along the current URL as a query string, which provided an easy [...]
Rails background process - simple, fast, easy.
My situation was this -
Rails 2.0 app running on slicehost (ubuntu 8.04) in passenger mod_rails
The goal was Dynamic PDF generation for a product catalog ( > 100 pages)
This event had to be triggered from within the rails request / response cycle, but run outside of it
I needed the simplest, fastest, more reliable way for this [...]
mod_rails set RAILS_ENV variable to QA, Staging, or Production
I’m using mod_rails with capistrano and multi-stage (qa, staging, production), and wrote this workaround so that the RAILS_ENV could be set correctly in each stage. Mod_rails sets RAILS_ENV once in the global server conf file, but I needed it set once for each environment: qa, staging, and production. I tried setting ENV['RAILS_ENV] in each file [...]