Archive for January, 2008

Acts_as_nested_set ActiveRecord rendered with mx:Tree in Flex

Gr8 post by Daniel Wanja for Use acts_as_nested_set with Flex.
ActiveRecord: app/models/category.rb
 
app/models/category.rb
class Category < ActiveRecord::Base
acts_as_nested_set
end
Controller: app/controllers/categories_controller.rb
 
app/controllers/categories_controller.rb
class CategoriesController < ApplicationController
def index
Category.result_to_attributes_xml(Category.root.full_set)

end
end
Flex Application: ActsAsNestedSet.mxml
 
ActsAsNestedSet.mxml
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”
layout=”vertical”
applicationComplete=”categories.send()”>
<mx:HTTPService id=”categories” url=”http://localhost:3000/categories” resultFormat=”e4x” />
<mx:Tree dataProvider=”{categories.lastResult}”
labelField=”@name”
[...]

Rails REST meets Rails 2.0

Hey, I got a very good post posted by Jeff on http://www.softiesonrails.com/.
I think this will be helpful to me and all rails developers who uses Rails 2.0 which is most REST oriented
We developed those articles when 1.2 was a mature, stable release, and when it had also become clear that 2.0 would not significantly change [...]

Deploying two rails application with Apache + mongrel on windows

Install Ruby, Gems and then install Ruby on Rails:

sudo gem install rails –include-dependencies
Now download and install Apache 2.2 using, as the fastest way, the msi package.
Now enable the needed modules (url rewriting, proxy, proxy_balancer e proxy_http) by editing the httpd.conf file (under c:\Apache_Software_Foundation\Apache2.2\conf, if you installed Apache in its standard path). You just need to [...]

Add sql session store to rails application

Only Mysql, Postgres and Oracle are currently supported (others work, but
you won’t see much performance improvement).
Step 1
If you have generated your sessions table using rake db:sessions:create, go
to Step 2
If you’re using an old version of sql_session_store, run
script/generate sql_session_store DB
where DB is mysql, postgresql or oracle
Then run
rake [...]

Add + in URL insteade of space (%20)

This is a workaround to get spaces in URL as pluses not %20 like it is in Rails2.
module ActionController::Routing
class DynamicSegment
def interpolation_chunk
“\#{CGI.escape(#{local_name}.to_s)}”

end

def match_extraction(next_capture)
default_value = default ? default.inspect : nil

[...]

Shorcuts for kill and restart rails server

More lovely alias commands… this time to kill/restart Rail’s script/server from any Terminal session or login on your box… (as long as your the same user).
alias dierails=’ps -a|grep “/usr/local/bin/ruby script/server”|grep -v “grep /usr”|cut -d ” ” -f1|xargs -n 1 kill -KILL $1′
alias resetrails=’ps -a|grep “/usr/local/bin/ruby script/server”|grep -v “grep /usr”|cut -d ” ” -f1|xargs -n 1 [...]