Sean Chittenden – Ruby on Rails Podcast

Sean Chittenden talks about his Rails re-design work with Penny-Arcade.com, server scalability, and the open source business model.

Sean Chittenden – Ruby on Rails Podcast

Sean Chittenden talks about his Rails re-design work with Penny-Arcade.com, server scalability, and the open source business model.

inline RJS

In my previous article I was playing with RJS templates and finding easy way to generate them. Well Thomas just posted some new goodies see http://mir.aculo.us/articles/2006/01/21/new-inline-rjs-for-rails. For quick updates no need to have a separte .rjs file.

class UserController < ApplicationController
def refresh
render :update do |page|
page.replace_html(‘user_list’,
:partial => ‘user’, :collection => @users)
page.visual_effect :highlight, ‘user_list’
end
end
end

.rjs and link_to_function

A neat little trick is that .rjs templates can be used to generate local javascript functions and be invoked without doing a server roundtrip.

playground_controller.rb

class PlaygroundController < ApplicationController
def rjs
response.headers[‘content-type’] = ‘text/html’
end
end

rjs.rhtml



<%= javascript_include_tag :defaults %>

Javascript function test

<%= link_to_function(‘Add’, ‘add_item()’ ) -%> |
<%= link_to_function(‘Clear’, ‘clear_list()’) >

Scott Raymond – Ruby on Rails Podcast

Scott Raymond, developer of Blinksale, Icon Buffet, and other wonderful Rails apps.

Scott Raymond – Ruby on Rails Podcast

Scott Raymond, developer of Blinksale, Icon Buffet, and other wonderful Rails apps.

Xml Builder

I created the new Playground category on this blog to expose various aspects regarding Ruby On Rails that I am exploring. It may raise more questions than provide answers, but in any case don’t hesitate to jump in and add your 2 cents.

The xml_builder method here after uses the render_to_string method to create some xml structure. The xmlstring could as well have been in a separate .rxml file and and a simple render statement instead of render_as_string could have saved one line of code. But hey, that’s what the playground is for!

class PlaygroundController < ApplicationController
def xml_builder
xml_string = <<-XML_END
xml.test do
xml.language(name)
xml.description(“Rocks!”)
end
XML_END
result = render_to_string(:inline => xml_string, :locals => { :name => ’Ruby’}, :type => :rxml)
render_text result
end

end

The output:


Ruby
Rocks!

Flex vs. ROR

Ed just asked me: "Why, ultimately would you say ROR is better than Flex? There’s a great debate at the moment.

My swiss style answer: "This is a very interresting question. I effectively use
both technologies with different customers on different projects. And
I like both, they have different strength. Flex 1.5 answers only the
UI question and doesn’t help with the persistence side of a project.
Flex 2.0 will provides some answers to the persistence integration
with their Enterprise Services. Flex is really awesome to build a
custom UI. Rails on the other hand provides lots of power if you have
control on the database schema and is a full “web” stack. It provides
a nice framework to build the views and provides some pretty powerfull
ways to create dynamic html pages. Rails can we very productive. So in
other words, I don’t prefer one over the other. It really depends on
the specifics of the problem to be solved, the technical expertise of
a customer and the future direction a customer wants to go to define
if one technology is more appropriate than another."