simply_helpful插件为我们添加了许多helper方法,例如:
1,render partial
以前我们这样写:
[code]
<table>
<tr><th>Name</th><th>City</th><th>Postcode</th></tr>
<%= render :partial => 'venue', :collection => @venues %>
</table>
[/code]
现在可以这样写:
[code]
<table>
<tr><th>Name</th><th>City</th><th>Postcode</th></tr>
<%= render :partial => @venues %>
</table>
[/code]
2,DOM ID/DOM Class names
[code]
<%= dom_id(object, prefix = nil) %>
[/code]
生成的DOM对象的ID的格式为person_123或者new_person
我们在RJS里也可以使用该helper方法,如下三种方式是等同的:
[code]
page[:person_123]
page[dom_id(@person)]
page[@person]
[/code]
3,Form block
新的form_for语法与RESTful Routes集成来大大简化form代码:
1,form的action是update还是create取决于对象以前是否save过
2,form自动得到一个id,如new_venue或edit_venue_123,这取决于form为new还是update
3,form自动得到一个class name,如new_venue或edit_venue
这样一来,form_for的动态性让我们可以只用一行代码搞定new和edit两种表单:
[code]
<% form_for @venue do |f| %>
[/code]
BTW:simply_restful began its life as a plugin, and at RailsConf, the core team announced that it would be merged into Rails core.
1,render partial
以前我们这样写:
[code]
<table>
<tr><th>Name</th><th>City</th><th>Postcode</th></tr>
<%= render :partial => 'venue', :collection => @venues %>
</table>
[/code]
现在可以这样写:
[code]
<table>
<tr><th>Name</th><th>City</th><th>Postcode</th></tr>
<%= render :partial => @venues %>
</table>
[/code]
2,DOM ID/DOM Class names
[code]
<%= dom_id(object, prefix = nil) %>
[/code]
生成的DOM对象的ID的格式为person_123或者new_person
我们在RJS里也可以使用该helper方法,如下三种方式是等同的:
[code]
page[:person_123]
page[dom_id(@person)]
page[@person]
[/code]
3,Form block
新的form_for语法与RESTful Routes集成来大大简化form代码:
1,form的action是update还是create取决于对象以前是否save过
2,form自动得到一个id,如new_venue或edit_venue_123,这取决于form为new还是update
3,form自动得到一个class name,如new_venue或edit_venue
这样一来,form_for的动态性让我们可以只用一行代码搞定new和edit两种表单:
[code]
<% form_for @venue do |f| %>
[/code]
BTW:simply_restful began its life as a plugin, and at RailsConf, the core team announced that it would be merged into Rails core.
本文介绍了Simply_Helpful插件如何简化Rails应用开发,包括简化渲染部分模板的方法、生成DOM ID和类名的方式以及form_for语法的增强。这些改进使得开发者能够更高效地编写代码。

被折叠的 条评论
为什么被折叠?



