JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Languages on JVM » JRuby  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Rails 1.1
contagious





發文: 12
積分: 2
於 2006-03-29 16:44 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
rails 1.1 在昨天 (2006/03/28) 正式發表了

下面是根據 release note 和 cap 兄的文章所做的概述:

這是 rails 史上最大的一次更新,來自100位貢獻者,超過500個小修改,錯誤修正和新功能。
雖然大部份的修改只是讓你的生活更好過一點,但是也許多有震撼人心的新功能:

受矚目的 RJS

用 Ruby 來寫 Javascript:來自 Ruyb/Javascript 大師 Sam Stephenson 的 RJS 讓你不用再搞令人沮喪的 Javascript了!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  # First buy appears the cart, subsequent buys highlight it
  page[:cart].visual_effect(@cart.size == 1 ? :appear : :highlight)
 
  # Replace the cart with a refresh rendering of the cart partial
  page[:cart].replace_html :partial => "cart" 
 
  # Highlight all the DOM elements of class "product" 
  page.select(".product").each do |element|
    element.visual_effect :highlight
  end
 
  # Call the custom JavaScript class/method AddressBook.cancel()
  page.address_book.cancel
 
  # 4 seconds after rendering, set the font-style of all company
  # spans inside tds to normal
  page.delay(4) do
    page.select("td span.company").each do |column| 
      column.set_style :fontStyle => "normal" 
    end
  end


RJS 相關連結
* RJS API
* element and collection proxies
* RJS tutorial
* Ajaxed forms with RJS templates
* Real-world Rails RJS templates

(順帶一提,Cody Fauser 會幫 O’Reilly 寫一本 RJS 的書..)


contagious edited on 2006-03-29 17:44
reply to postreply to post
作者 Re:Rails 1.1 [Re:contagious]
contagious





發文: 12
積分: 2
於 2006-03-29 16:55 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
ActiveRecord 的新把戲
* Bottomless eager loading:從資料庫一次把相關的資訊都拿出來,節省多小小的 query 了
1
2
3
4
5
6
 # Single database query:
  companies = Company.find(:all, :include => { 
    :groups => { :members=> { :favorites } } })
 
  # No database query caused:
  companies[0].groups[0].members[0].favorites[0].name


* polymorphic associations: 多型關連?看例子:
1
2
3
4
5
6
7
8
9
10
11
 class Address < ActiveRecord::Base
    belongs_to :addressable, :polymorphic => true
  end
 
  class Person < ActiveRecord::Base
    has_one :address, :as => :addressable
  end
 
  class Company < ActiveRecord::Base
    has_one :address, :as => :addressable
  end


Address 可以同時是 Person 的屬性也是 Company 的屬性!!

* join models: 丟掉醜陋的 has_and_belong_to_many 吧,用 :through 更加的清楚明白
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  class Author < ActiveRecord::Base
    has_many :authorships
    has_many :books, :through => :authorships
  end
 
  class Book < ActiveRecord::Base
    has_many :authorships
    has_many :authors, :through => :authorships
  end
 
  class Authorship < ActiveRecord::Base
    belongs_to :author
    belongs_to :book
  end


*to_xml:每個 model 都可以直接輸出成 xml

*Calculation:常對資料作的一些計算 ( average, count, maximum, minimum, sum) 都包裝起來了。

* 現在還多支援 Sybase 和 OpenBas 兩種資料庫


reply to postreply to post
作者 Re:Rails 1.1 [Re:contagious]
contagious





發文: 12
積分: 2
於 2006-03-29 17:24 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
其它
* respond_to: 根據 HTTP 的 Accept header 來決定要回應什麼樣的內容
# DHH 說 respond_to
# JamiesBuck 教 respond_to
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  class WeblogController < ActionController::Base
    def create
      @post = Post.create(params[:post])
 
      respond_to do |type|
        type.js   { render }  # renders create.rjs
        type.html { redirect_to :action => "index" }
        type.xml  do
          headers["Location"] = post_url(:id => @post)
          render(:nothing, :status => "201 Created")
        end
      end
    end
  end

* [url =http://jamis.jamisbuck.org/articles/2006/03/09/integration-testing-in-rails-1-1] Integration test[/url]

* 其它的改變請參考這裡這裡


reply to postreply to post
作者 Re:Rails 1.1 [Re:contagious]
contagious





發文: 12
積分: 2
於 2006-03-29 17:31 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
如何昇級

用 gem 來昇級真是方便!

先昇到 Rake 0.7
> gem update rake

再昇到 Rails 1.1:
> gem update rails --include-dependencies

記得把舊的 gem 清掉
> gem clean

舊的程式裡,可以這樣更新 RJS 相關的 Javascript
> rake rails:update

注意 :
1. 在 windows 上不支援 Ruby 1.8.2 了喔!
2. 不相容的部份大多在 plugin 身上,請自行到 plugin 的網站查詢昇級的注意事項


reply to postreply to post
作者 Re:Rails 1.1 [Re:contagious]
cpi





發文: 12
積分: 0
於 2006-03-30 14:25 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
RJS 真是個不錯的點子!

一般開發 AJAX 程式免不了要在 HTML 上寫一些 javascript 動動 DOM.

RJS 的方法將 HTML 用 "page" instance variable 給你, 把一些 prorotype/scriptaculous 用來處理 DOM/effect... 的方法 proxy 給你
用來處理 page. 並且透過 AJAX 傳回配合 prototype/scriptaculous
就會幫你執行好好...

以前我們對每個 AJAX request 都要有對應的 views, 但 views 又很簡單
搞的系統一堆 views, 用程式方法來解決這個問題很簡潔又快速!

棒!!!


cpi edited on 2006-03-30 15:12
reply to postreply to post
» JWorld@TW »  Languages on JVM » JRuby

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8