Run your Ruby on Rails app on Google app engine
April 25th, 2009
Run your Ruby on Rails app on Google app engine .
Yeah its possible to run RoR base application on GAE/J Thanks to jruby .
Limitations :
NO activerecord
10000 files maximum
10 MB max file size
Steps
you should have jruby already jruby 1.3 =< installed
1: Install rails , warbler and appengine-apis
Jruby -S gem install rails warbler appengine-apis
2: checkout template rails app with datamapper
git clone git://github.com/dkubb/datamapper-on-rails.git
3: comment out the following lines in config/environment.rb
config.gem ‘rails’ config.gem ‘appengine-apis’
4: change to you app dir
5: pluginize your app
jruby -S warble pluginize
6: generate configs
jruby -S warble config
7: edit config/warble.rb
config.webxml.jruby.min.runtimes = 1 config.webxml.jruby.max.runtimes = 1 config.webxml.jruby.init.serial = true config.java_libs = []
8: generate war
jruby -S warble
Rspec custom matchers for Rails
January 26th, 2009
module Spec
module Rails
module Matchers
# check if the xpath exists one or more times
class HaveXpathText
def initialize(xpath,text)
@xpath = xpath
@text = text
@text_returned = ""
end
def matches?(response)
@response = response
doc = response.is_a?(Hpricot::Doc) ? response : Hpricot::XML(@response)
begin
@text_returned= (doc/@xpath).inner_text.strip
if @text_returned == @text.to_s
true
else
false
end
rescue
return false
end
end
def failure_message
# "Did not match expected xpath #{@xpath} text #{@text}"
"Did not match expected xpath #{@xpath} text #{@text_returned} with #{@text}"
end
def negative_failure_message
"Did find unexpected xpath #{@xpath} text #{@text}"
end
def description
"match the xpath expression text #{@xpath}"
end
end
def have_xpath_text(xpath,text)
HaveXpathText.new(xpath,text)
end
end
end
Rspec Tutorial
January 5th, 2009
Rspec
Ruby Behavior driven development is Rpec. We will explore how to write specs with rspecs . we will not use yml fixture . yml fixtures sucks instead we use machinist and will use mocha as mocking framework
I assume you are on Mac or Linux .
First install rspec
sudo gem install rspec
then install rpsec-rails
sudo gem install rspec-rails
rails my_app
cd my_app
ruby script/generate rspec
cd spec
spec folder is home folder for all of you spec data for you app
So here is Mephisto xmlrpc plugin for Mephisto release 0.8 and for Mephisto Edge.
I have ported original Mephisto_xmlrpc plugin to work with Mephisto 0.8 and Mephisto edge.
The Original plugin was not compatible with most of the Desktop blogging tool if you use metaweblog api. this plugin working with almost all popular blogging tools like ecto, marsedit, blogtk, gnome-blog etc. , even with google reader.
checkout Mephisto xmlrpc plugin from subversion, this is available two flavors .
for Mephisto release 0.8
script/plugin install http://svn.railshacks.com/projects/mephisto/plugins/mephisto_xmlrpc_0.8
for Mephisto edge
script/plugin install http://svn.railshacks.com/projects/mephisto/plugins/mephisto_xmlrpc_edge
To install Mephisto xmlrpc plugin
follow these steps
1: edit file app/controllers/application/error.rb
locate these lines
rescue_from ActiveRecord::RecordNotFound, :with => :render_admin_not_found
rescue_from ActionController::UnknownController, :with => :render_admin_not_found
rescue_from ActionController::UnknownAction, :with => :render_admin_not_found
change these lines to
rescue_from ::ActiveRecord::RecordNotFound, :with => :render_admin_not_found
rescue_from ::ActionController::UnknownController, :with => :render_admin_not_found
rescue_from ::ActionController::UnknownAction, :with => :render_admin_not_found
save the file .
2: checkout action web service from svn repo. into vendor/rails folder.
svn co http://svn.rubyonrails.org/rails/ousted/actionwebservice/
3. restart your server
Now you have working xmlrpc service at your server .
if you face any problem installing/using this plugin feel free to ask .
mephisto sitemap plugin
July 10th, 2008
Mephisto has always been my favourite rails publishing system , few days back I switched to mephisto edge, later i found most of mephisto plugins are broken on mephisto edge because mephisto edge is using rails engine system ,
So I ported Stephen Caudill's existing mephisto sitemap plugin on mephisto edge and now its available at http://svn.railshacks.com/projects/mephisto/plugins/mephisto_sitemap/
Currently I am looking at other plugins that is not compatible with mephisto edge , As soon as i complete I will make it available for public download
if you face any problem please make a comment here
Ruby on Rails exception notification through mail
June 19th, 2008
So you want to get notified when you get exception on production application environment , lets do in three easy steps
1: create a action mailer model
class Mymailer '
@subject = "[Error] exception in #{env['REQUEST_URI']}"
@sent_on = time
@body["exception"] = exception
@body["trace"] = trace
@body["session"] = session
@body["params"] = params
@body["env"] = env
content_type("text/html")
end
end
2: define this method in you application.rb file
def log_error(exception)
super(exception)
begin
if ENV['RAILS_ENV'] == 'production'
Notifier.deliver_error_page(exception,
clean_backtrace(exception),
@session.instance_variable_get("@data"),
@params,
@request.env)
end
rescue => e
logger.error(e)
end
end
3: create a view file view/mymailer/error_mail.html.erb
now you have access to these files , you can format your mail as you feel like
@body["exception"] # exception
@body["trace"] # trace
@body["session"] # session
@body["params"] # params
@body["env"] # env
now you have working exception handling system
if face any problem make a comment here
top 5 Ruby on Rails CMS
June 10th, 2008
Rails: Cross Database development
June 1st, 2008
Its a piece of cake developing applications that run on multitude of Database management solutions. All you need to keep Database schema scripts handy. Here is how you do it using rails scripts:
ruby script\generate migration Contact
This will create an empty file in db/migrate folder for contact table. You need to fill it now with the fields you want for eg:
class Contact < ActiveRecord::Migration def self.up create_table :contacts do |table| table.column :first_name, :string table.column :last_name, :string table.column :email, :string table.column :phone, :string table.column :address, :string end end def self.down end end
ruby script\generate scaffold Contact
Ok.. just found what I was looking for. Pretty detailed document for this: http://rubyonrails.org/api/classes/ActiveRecord/Migration.html
Now, apply the migration
rake migrate
Now, generate model and controller for Contact
ruby script\generate scaffold Contact
I got this error today while deploying rails application on running lighttpd server. Errno::ENOENT (No such file or directory – getcwd) I replaced application directory without stopping lighty and got error while trying accessing app via browser. I went off by merely restarting lighthttpd :)
Seems like server creates/uses some file “within” rails app folder which got erased while replacing the folder.
Rails RJS redirect
May 4th, 2008
page.redirectto :action => ‘thanks’, :p1 => @gresp.params[”code”], :p2 => @rid
Rails RJS redirect
May 4th, 2008
page.redirect_to :action => ‘thanks’, :p1 => @g_resp.params[”_code”], :p2 => @r_id
ERROR: While executing gem … (Gem::GemNotFoundException)
May 3rd, 2008
You might be feeling annoyed with this problem. (I do) Problem could be:
your local source cache Example: /usr/lib/ruby/gems/1.8/source_cache
; try removing this file (Your path might be different than above given; check your path first using #gem env) If this does not solves your problem
check your env var REMOTE SOURCES (#gem env)
If it is not gems.rubyforge.org then use following command to install:
gem install -r gem_name –source http://gems.rubyforge.org
If this does not solves your problem(is your internet down?)
Borrow gem files from your friend and install them without -r option.