Posts

Showing posts with the label rails

Ruby on Rails and App Engine Performance Sample

Image
Statistics are always dangerous, and YMMV, but I wanted to post a set of performance tests I recently ran on a sample (and simple) Ruby on Rails application hosted on App Engine . These numbers are after the application has warmed up, and I've tried to make this test show results under the best real life circumstances. Ruby on Rails applications do have a higher than normal start-up time on App Engine, an issue acknowledged and currently worked on. After they are warmed up, however, users shouldn't experience a difference. The test was driven from the ab command, a simple benchmarking tool that comes with any Apache HTTPD software install. I ran the test from a Rackspace Cloud virtual machine. The Rails code for this test can be found on Github . Specifically, the controller and action being run in the test: class ContactsController Note: the database is empty for this test. Network latency between Rackspace Cloud and Google App Engine: sladd@slice84717:~...

Rails Backwards Incompatible Change Coming to 2.3, Application is Now ApplicationController

Just a head's up to Ruby on Rails fans out there. DHH just checked in a very backwards incompatible change for the 2.3 branch. The root class for your controllers is now ApplicationController and not Application . I'm hoping this patch is reverted and instead rolled out for 3.0.

Issues with Active Scaffold and Rails 2.1, Solved

If you are looking to upgrade to Rails 2.1 and you are using Active Scaffold , be aware it still has a few rough edges. Make sure you install the Rails 2.1 branch of Active Scaffold: git clone git://github.com/activescaffold/active_scaffold cd active_scaffold git branch -r (just lists the branches) git checkout origin/rails-2.1 (Check out the full thread for Rails 2.1 and Active Scaffold compatibility ) Second, I had to patch vendor/plugins/active_scaffold/lib/extensions/generic_view_path.rb . On line 53, make it look like this: if [email protected]_a?(ActionMailer::Base) && @template.controller.class.uses_active_scaffold? I had to add [email protected]_a?(ActionMailer::Base) && All my tests are now passing! I still love Active Scaffold, even though it's a bit behind the times.

worldofresources.pdf (application/pdf Object)

Resources on Rails highlights some of the new exciting changes to appear in Rails 1.2. The most exciting is ActiveResource, which CRUDifies models as HTTP resources. Go REST!

Java.net App Hosting

Hong Zhang's Blog mentions that java.net is now hosting J2EE applications for free through LocalWeb . Here's the quote that scares me: > The actual deployment of an application is done by a small team of engineers from Sun. Yikes. Even with all the deployment descriptors, it takes "a small team" to host and deploy a single J2EE application. There's something wrong with that. I've always said that deploying Java applications is Java's Achilles Heel. The LAMP community mocks Java not necessarily because the language is more verbose, but because it's so dang hard to deploy the applications. Compare with PHP, which is as easy as editing the file and then hitting reload in your browser. That's nearly impossible with a full J2EE application. So many libraries have memory leaks that play havoc with classloaders that a full application server restart is required. In any case, this is one of the main reasons I've been moving to Rails. I ca...

Rails and Allowing ID Editing from Forms

Need to allow yours users to directly edit the ID of your model object? By default, Rails will strip out the ID field from the hash of request parameters. This is a security measure, prohibitings the web interface from altering an object's ID. Generally, this is a good practice. However, some legacy schemas have IDs that are not simply numbers. In those cases, the ID is created and managed by the user. To tell Rails to allow the ID to be edited, you can use attr_protected and attr_allowed . More information is available at http://wiki.rubyonrails.com/rails/pages/HowToEnsureValidAttributesInFormData

Rails, Legacy Schemas, ActiveRecord, and has_and_belongs_to_many

There turns out to be an issue with legacy schemas and ActiveRecord , the ORM layer of Rails when using has_and_belongs_to_many . Note: This issue might be Oracle specific. If the join table itself has an id column, and it has the same name as the id column from the association table, then it will override the id from the association table. This means that instances from the association table will have the wrong id. The solution looks to be the new :finder_sql parameter of the has_and_belongs_to_many relationship. With :finder_sql , you can override the generated SQL. How to use :finder_sql ? Try: has_and_belongs_to_many :ksaas, :join_table => "tbl_ksaa_objective", :foreign_key => "objective_cid", :association_foreign_key => "ksaa_cid", :finder_sql => "SELECT TBL_KSAA.cid, TBL_KSAA.ksaa_type, TBL_KSAA.ksaa_item, " + "TBL_KSAA.KSAA_TYPEID, TBL_KSAA.SAMPLE_BEHAVIOR " + "FROM TBL_KSAA LEFT JOIN TBL_KSAA_...

Named Routes in Rails

From Ronny Haryanto via the Rails Mailing List: Interested in URLs that look something like this? http://www.example.com/project/submarine You can tell Rails to parse that URL in order to call the appropriate method on the controller.  You might be interested in Named Routes. http://wiki.rubyonrails.com/rails/pages/NamedRoutes In config/routes.rb:    map.project 'project/:projtitle' :controller => 'project',                                     :action => 'show' In app/controllers/project_controller.rb:    def show      @project = Project.find(:first,                              :conditions => ['title = ?',params[:projtitle]])      ...    end Or something like that. Assuming your project titles are unique. Then you can also use project_url (since you h...

Using Columns with Reserved Names in Rails

From Rails Mailing List : How to access column with a reserved name? def new_column read_attribute 'old_column' end def new_column=(value) write_attribute 'old_column', value end

Testing with Rails

A hint with writing tests with Ruby on Rails.  If you are using fixtures, the name of the fixture is the name of the database table, not the name of the model under test. For instance, this code: class TaskTest < Test::Unit::TestCase   fixtures :tbl_task The symbol :tbl_task is the name of the database table.

Adjust Log Level in Ruby on Rails

To adjust your log level for a Rails project, you have two options. Edit config/environment.rb and set a global log level. This will override all environments (development, production, etc). Edit config/environments/production.rb , for instance to change production's log level. This is recommended. Simply add the line config.log_level = :warn to set WARN level. This will greatly decrease the amount of logging performed.