每天一剂Rails良药之simply_helpful

simply_helpful插件为我们添加了许多helper方法,例如:
1,render partial
以前我们这样写:
<table>
  <tr><th>Name</th><th>City</th><th>Postcode</th></tr>
  <%= render :partial => 'venue', :collection => @venues %>
</table>

现在可以这样写:
<table>
  <tr><th>Name</th><th>City</th><th>Postcode</th></tr>
  <%= render :partial => @venues %>
</table>


2,DOM ID/DOM Class names
<%= dom_id(object, prefix = nil) %>

生成的DOM对象的ID的格式为person_123或者new_person
我们在RJS里也可以使用该helper方法,如下三种方式是等同的:
page[:person_123]
page[dom_id(@person)]
page[@person]


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两种表单:
<% form_for @venue do |f| %>


BTW:simply_restful began its life as a plugin, and at RailsConf, the core team announced that it would be merged into Rails core.

你可能感兴趣的:(F#,Rails)