Questions tagged «partial»

5
Rails使用块渲染部分
我试图重新使用我编写的提供面板样式的html组件。就像是: <div class="v-panel"> <div class="v-panel-tr"></div> <h3>Some Title</h3> <div class="v-panel-c"> .. content goes here </div> <div class="v-panel-b"><div class="v-panel-br"></div><div class="v-panel-bl"></div></div> </div> 因此,我看到渲染占用了一个块。我想然后我可以做这样的事情: # /shared/_panel.html.erb <div class="v-panel"> <div class="v-panel-tr"></div> <h3><%= title %></h3> <div class="v-panel-c"> <%= yield %> </div> <div class="v-panel-b"><div class="v-panel-br"></div><div class="v-panel-bl"></div></div> </div> 我想做类似的事情: #some html view <%= render :partial => '/shared/panel', :locals …


7
是否有任何Rails函数来检查是否存在部分?
当我渲染不存在的部分时,出现异常。我想在渲染之前检查部分是否存在,如果不存在,我会渲染其他东西。我在.erb文件中执行了以下代码,但我认为应该有更好的方法: <% begin %> <%= render :partial => "#{dynamic_partial}" %> <% rescue ActionView::MissingTemplate %> Can't show this data! <% end %>

4
Rails:分部应该知道实例变量吗?
例如,瑞安·贝茨(Ryan Bates)的nifty_scaffolding edit.html.erb <%= render :partial => 'form' %> new.html.erb <%= render :partial => 'form' %> _form.html.erb <%= form_for @some_object_defined_in_action %> 这种隐藏状态使我感到不舒服,所以我通常喜欢这样做 edit.html.erb <%= render :partial => 'form', :locals => { :object => @my_object } %> _form.html.erb <%= form_for object %> 那么哪个更好:a)使局部变量访问实例变量,或者b)传递局部变量所需的所有变量? 到目前为止,我一直在选择b),但确实遇到了一些泡菜: some_action.html.erb <% @dad.sons.each do |a_son| %> <%= …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.