My first rwt application in rails 3
How I put rwt to work with rails 3
I was wondering if rwt would work with rails 3. For my surprise, it worked. Here are the steps I followed:
- Create a new rails 3 application:
$ rails -v Rails 3.0.1 $ rails new rwt_in_rails3 create create README create Rakefile create config.ru create .gitignore create Gemfile create app create app/views/layouts/application.html.erb ... create tmp/pids create vendor/plugins create vendor/plugins/.gitkeep - Install the rwt plugin and the ExtJs javascript library
$ cd rwt_in_rails3/public $ wget http://www.extjs.com/deploy/ext-3.3.0.zip $ unzip ext-3.3.0.zip $ mv ext-3.3.0 ext $ rm ext-3.3.0.zip $ cd ../vendor/plugins $ git clone git://github.com/smbrant/rwt.git
- Create a new controller with two actions
$ cd ../.. $ rails g controller desktop index test
- Remove the application.html.erb file
$ mv app/views/layouts/application.html.erb app/views/desktop/index.html.erb
- and edit app/views/desktop/index.html.erb like this:
<!DOCTYPE html> <html> <head> <title>Testing Rwt in Rails3</title> <link rel="stylesheet" type="text/css" href="/ext/resources/css/ext-all.css" /> <script type="text/javascript" src="/ext/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="/ext/ext-all.js"></script> <script src="/desktop/index.rwt" type="text/javascript"></script> <%= csrf_meta_tag %> </head> <body scroll='no'> </body> </html> - Edit app/controllers/desktop_controller.rb like this:
class DesktopController < ApplicationController def index respond_to do |format| format.html format.rwt {rwt_render} end end def test respond_to do |format| format.html format.rwt {rwt_render} end end end - Now let's create our main rwt view, file app/views/desktop/index.rb:
rwt_app do toolbar do menu('Tests') do menu_item('First test',function("alert('hello!')")) menu_item('Second test',call_view('/desktop/test.rwt')) end end end - And a test window, defined in the rwt view app/views/desktop/test.rb:
window('My first window in rails3',200,200) do button('Show something') do |b| b.on('click') do message('Hello world') end end end - It's finished! Let's run it:
rails start
- Go to http://localhost:3000/desktop/index:

Comments