在grails中我这样做:
<form:windowEntrada domain="serverPool">
<form:entrada domain="serverLocation" bean="${serverPoolInstance}">
<form:textField label="serverPool.name" name="name" />
<form:select label="serverPool.server" name="server" list="${Servers.list()}"/>
</form:entrada>
</form:windowEntrada>
标签“form:textField”呈现如下内容:
<div class='field-name'>
<div class="title"><label for="name">Name</label>(* required)</div>
<div class="fieldcontent"><input type="text" name="name" value="smtg"></div>
<div class="error">If thereis an error on this field, the message appears here</div>
</div>
标签“form:windowEntrada”呈现如下内容:
<div class='container'>
<h1>My title here</h1>
<div class="content">${body()}</div>
</div>
标签“form:entrada”呈现如下内容:
<form action ... >
<....> --> messages stuff
${body()}
<div class="action-buttons">
<input type="submit" name="lala">
<input type="submit" name="lala2">
</div>
</div>
我如何使用erb作为我的视图技术?
谢谢。
答案 0 :(得分:1)
我在这里找到了答案:pathfindersoftware.com/2008/07/pretty-blocks-in-rails-views
以下是应用教程的示例:
在再培训局:
<%= widget("mytitle", {:class => "widget-table"}) do %>
test test test
<% end %>
在帮助者中:
def widget(title, options = {}, &block)
options[:params] = params
options[:controller_name] = controller.controller_name
body = capture &block
html = render "shared/form/widget", :body => body,
:title => title,
:options => options
return html
end
和模板_widget.html.erb:
<div class="widget <%= options[:class] unless options[:class].blank? %>">
<% unless title.blank? %>
<div class="widget-header">
<span class="icon-layers"></span>
<h3><%= title %></h3>
</div>
<% end %>
<div class="widget-content">
<%= body%>
</div>
</div>
TKS