render直接渲染视图, 即直接将页面render部分渲染成partial参数后面名字相同的_名字.html.erb文件
实际案例:
index.html.erb中:
#####render渲染的视图为coupon.status字段存的值的下划线_同名.html.erb文件进行对<td></td>标签内的渲染, coupon.status中存的值由两个一个是online一个是offline则只能导向这两个视图,创建两个下划线同名的视图,内容是对online和offline不同样式的显示则能使页面更加美观,当然用if else分支来显示不同样式也可以
<% @coupons.each do |coupon| %>
<tr>
<td><%= coupon.id %></td>
<td><%= coupon.coupon_type %></td>
<td><%= coupon.name %></td>
<td><%= coupon.start_time %></td>
<td><%= coupon.end_time %></td>
<td><%= coupon.value %></td>
<td><%= render :partial => coupon.status %></td>
<td><%= coupon.total_count %></td>
<td><%= coupon.got_count %></td>
<td><%= time_format coupon.created_at %></td>
<td>
<%= link_to "Edit", [:edit, :manage, coupon] %>
</td>
<td>
<%= link_to "Detail", manage_user_coupons_path(coupon)%>
</td>
</tr>
<% end %>
offline.html.erb中:
<div class="ui label">
offline
</div>
online.html.erb中:
<div class="ui green label">
online
</div>