Contacts is a sample application that demonstrates the integration of the OpenLaszlo client framework with the Ruby on Rails server framework. Contacts is a Ruby application, one of whose assets is an OpenLaszlo applet that uses REST and AJAX to communicate with the server.
Contacts is also a temporary container for the helpers and scaffolding that make it easy to integrate OpenLaszlo and Rails. (For now, these live in the 'vendors' subdirectory of the Contacts source distribution.) These helpers are intended to make it easy to add OpenLaszlo integration to your own application.
Both contacts, and these helpers, are pre-alpha code. A list of known omissions is at the bottom of the readme <http://osteele.com/sources/ruby/contacts/README>. Much of what's missing, however, is unknown. The helper files in contacts have only been used in this one application, without unit tests, and only for a few hours. I'm distributing this very early, so that enthusiasts can look at it while I continue to work on it.
As an example of how to use the helpers, the Contacts controller looks like this, in its entirety: require 'openlaszlo/rest_scaffolding.rb' require 'openlaszlo/rest_helper.rb'
class ContactsController < ApplicationController rest_scaffold :contact end
Wow. And I thought I was going to be getting some sleep tonight. Thanks, Oliver! This is awesome -- saves us weeks of work on doing some proof-of-concept stuff.
Two things have been bothering me that I think I have found a resolution for: binding to tables and where (or when) to allow arbitrary SQL calls.
I think that the problem I have with binding to tables is historical -- I have seen too many tools come out that treated a row in a table as a self-contained entitiy, as if real-world objects aren't the product of joining many tables. Anyway, Martin Fowler's description of ActiveRecord (the pattern) specifies that it is an object wrapper for a row from a table *or view*. That works for me. In Rails, we would just have to override the save method to update many tables (or call a stored proc, heaven forbid!) if the data source is actually a view or the product of a join. I just don't want to propogate the simplistic view that objects = table.rows all the time. That is just not the case.
When to allow SQL? I just learned last night from argv[0] on #rubyonrails that you can arbitrarily create a model object anytime you call find_by_sql. For example:
./script/console → s = ActiveRecord::Base.find_by_sql("SELECT 'hello' as word").first puts s.word
That is way cool. So, I think that our approach should be similar:
1. Design so that the developer never needs to resort to SQL 2. Allow the developer to resort to SQL all the time
Mike Pence
On 1/10/06, Oliver.Ste...@gmail.com <Oliver.Ste...@gmail.com> wrote:
> Contacts is a sample application that demonstrates the integration of > the OpenLaszlo client framework with the Ruby on Rails server > framework. Contacts is a Ruby application, one of whose assets is an > OpenLaszlo applet that uses REST and AJAX to communicate with the > server.
> Contacts is also a temporary container for the helpers and scaffolding > that make it easy to integrate OpenLaszlo and Rails. (For now, these > live in the 'vendors' subdirectory of the Contacts source > distribution.) These helpers are intended to make it easy to add > OpenLaszlo integration to your own application.
> Both contacts, and these helpers, are pre-alpha code. A list of known > omissions is at the bottom of the readme > <http://osteele.com/sources/ruby/contacts/README>. Much of what's > missing, however, is unknown. The helper files in contacts have only > been used in this one application, without unit tests, and only for a > few hours. I'm distributing this very early, so that enthusiasts can > look at it while I continue to work on it.
> As an example of how to use the helpers, the Contacts controller looks > like this, in its entirety: > require 'openlaszlo/rest_scaffolding.rb' > require 'openlaszlo/rest_helper.rb'
> class ContactsController < ApplicationController > rest_scaffold :contact > end
I've factored the OpenLaszlo helper and scaffolding code out from this application, into a Rails plugin. This makes it easier to use it in other applications. To use OpenLaszlo in a Rails application, do this: > gem install ropenlaszlo # In the application directory: > script/plugin install svn://rubyforge.org/var/svn/ropenlaszlo/rails/plugins/openlaszlo
And create a controller that looks like this: class ContactsController < ApplicationController rest_scaffold :contact end
I'm planning to work next on generators, a rake task, and a view helper, and then probably call it a day.
What I'm *not* working on, even though I'd very much like to see them, includes: * Writing a sexier example, such as an RSS reader * Writing an example that uses Create, Update, or Delete * Reviewing the REST spec * Matching the REST spec to this implementation, or vice versa (at least for now)
Oh yeah, I'm also not working on any OpenLaszlo components that consume this data. I believe that that (and some good demos) are what this project really needs in order to be compelling to people who aren't already sold on it.
Ok, I am confused. When you say "I'm also not working on any OpenLaszlo components that consume this data," do you mean that you are leaving this for others to do? Also, do you intend for this to be a complementary project to Laszlo on Rails?
Mike Pence
On 1/11/06, Oliver.Ste...@gmail.com <Oliver.Ste...@gmail.com> wrote:
> Oh yeah, I'm also not working on any OpenLaszlo components that consume > this data. I believe that that (and some good demos) are what this > project really needs in order to be compelling to people who aren't > already sold on it.
I'm happy to do this. I have a paging data controller that can help manage reads and be extended for updates and inserts.
I can also imagine a dynamic client-side view generator based on the /schema url. It would be very cool to be able get rails validation fields sent in schema requests for client-side validation.
Oliver.Ste...@gmail.com wrote: > Oh yeah, I'm also not working on any OpenLaszlo components that consume > this data. I believe that that (and some good demos) are what this > project really needs in order to be compelling to people who aren't > already sold on it.
Excellent start on the project! This gives us all a chance to "fiddle" with these latest developments and present something new and unique as a result. Start fiddling :)
I'm hoping the work that I'm doing can be used in Laszlo on Rails. I just meant that there are a lot of other parts of that project that I'm not planning to touch. Since I had charged ahead on some of the server-side integration pieces without any project coordination, I wanted to make it clear what the boundaries of the area that I'm trying to tackle this week.
I'm trying to do this in such a way that the same code could be used in the RSS reader you proposed, or a cookbook, or other applications --- although I'm sure you'll uncover bugs in in when you do this.
Sorry for the confusion. It was late at night (for me) when I wrote that.
Version 0.3 of the plugin and the demo app are available now.
Demo application: http://osteele.com/sources/ruby/contacts-0.1.zip OpenLaszlo gem: 'gem install ropenlaszlo' (this hasn't changed since yesterday) OpenLaszlo Rails plugin: "script/plugin install svn://rubyforge.org/var/svn/ropenlaszlo/rails/plugins/openlaszlo" (or "script/plugin update" if you've got it installed already)
The main changes are: * The plugin now installs the flashobject.js javascript file into public/javascripts (when you execute 'rake update_javascripts) * <%= javascript_include_tag :default %> includes flashobject.js by default. Or you can use <%= javascript_include_tag 'flashobject' %> if you just want the one file. * The plugin defines a tag <%= flashobject_tags 'applet'' %> that generates the HTML to include a Flash object. * The demo app uses these new features. It no longer includes its own copy of flashobject.js. * 'rake initialize' will do most of the demo app setup: create and seed the database tables, update javascripts, and compile the applet. You still need to create the database and database user (as with any rails application).
I'm planning to write some generators next and then put this on the back burner (at least, for me). Later today I'll jump on over to the basecamp project for a discussion of how best to make the sources available for collaborative development.
I don't anticipate any incompatabilities between this and future versions, so get coding!
Okay, version 0.4 of the plugin is available. This one adds generators for the controller, applet (LZX source file), and view: > script/generate rest_controller contacts > script/generate applet contacts applet
The default applet doesn't *do* anything, and you still need to edit your rakefile to manually add tasks to compile the applet. And the failure mode for forgetting to do any of this is just that nothing appears. Once these things are fixed, I'll make a new top-level announcement on this mailing list, that ties all this back together.
After that, I think we should bang on this for a while in our little closed community, and then add these to the plugin and generator sections of the Rails wiki once we know that they work. I'd like to redirect the docs for these to laszloonrails.com before that too. Maybe we can also put the rdoc for these packages up there.
Hi i cant seem to installt the plugin. i have installed ropenlaszlo 0.2 but the script/plugin install command throws me the following
E:\Eclipse_Projects\ropenlaszlo>ruby script/plugin install svn://rubyforge.org/v ar/svn/ropenlaszlo/rails/plugins/openlaszlo script/plugin: No such file or directory - svn --version c:/ruby/lib/ruby/1.8/open-uri.rb:87:in `initialize': Invalid argument - svn://ru byforge.org/var/svn/ropenlaszlo/rails/plugins/openlaszlo (Errno::EINVAL) from c:/ruby/lib/ruby/1.8/open-uri.rb:87:in `open_uri_original_open' from c:/ruby/lib/ruby/1.8/open-uri.rb:87:in `open' from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/plugin.rb:8 15:in `fetch_dir' from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/plugin.rb:8 09:in `fetch' from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/plugin.rb:8 08:in `each' from c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0