`
CaiDeHen
  • 浏览: 90520 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

#100 5 View Tips

阅读更多
Tip #1: Whitespace in ERB Templates
Use a dash at the beginning and end of an ERB tag to remove the white space around it.

<div id="products">
  <%- for product in @products -%>
    <h3><%=h product.name %></h3>
  <%- end -%>
</div>


Tip #2: content_for :side
You can use the content_for method in your template to store up code to use later on in the layout.

<!-- index.html.erb -->
<% content_for :side do %>
  ...
<% end %>

<!-- application.html.erb -->
<div id="side">
  <%= yield(:side) || render(:partial => '...' %>
</div>


Tip #3: Debugging Variables in Views
Pass a variable to the debug method to get the full details.

<%= debug @products %>
<%= debug params %>
<%= debug request.env %>


Tip #4: The Different Form Helpers
Rails comes with a lot of different helper methods dealing with forms. Here’s a quick tip on deciding which ones to use. If the form is editing a model, use the helper methods which do not end in the word “tag”. If you aren’t editing a model (such as a search form) then do use helpers which end in tag.

<!-- index.html.erb -->
<% form_tag products_path, :method => :get do %>
  <p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag "Search", :name => nil %>
  </p>
<% end %>

<!-- new.html.erb -->
<% form_for @product do |f| %>
  <p>
    <%= f.label :name %>
    <%= f.text_field :name %>
  </p>
  <p><%= f.submit "Create" %></p>
<% end %>


Tip #5: Optional Locals in Partials
If you want to make a :locals argument passed to a partial optional, you can move it into a helper method and give it a default value there.

<%= display_product @product, :show_price => true %># in helper
def display_product(product, locals = {})
  locals.reverse_merge! :show_price => false
  render :partial => product, :locals => locals
end
分享到:
评论

相关推荐

    ytongshang#AndroidTips#04_事件分发基础1

    如何判断一个点击事件是否在一个View的内部一般情况下,我们会直接判断是否在View范围的内部,但是有的时候我们需要考虑触摸范围//下面代码来源于View的hi

    Android代码-kotlin_tips

    怎么用Kotlin去提高生产力:Kotlin Tips 汇总Kotlin相对于Java的优势,以及怎么用Kotlin去简洁、务实、高效、安全的开发,每个tip都有详细的说明和案例代码,争取把每个tip分析得清楚易懂,会不断的更新维护tips,...

    Learning Representation for Multi-View Data Analysis

    This book equips readers to handle complex multi-view data representation, centered around several major visual applications, sharing many tips and insights through a unified learning framework....

    Android代码-debug_view_kotlin

    推荐项目kotlin_tips,用Kotlin去提高生产力:汇总Kotlin相对于Java的优势,以及怎么用Kotlin去简洁、务实、高效、安全开发的Tips 推荐项目easy_mock_api,给客户端同学的模拟json接口的小工具 推荐项目CompatWebView...

    Android高亮显示Tips视图

    源码ShowTipsView,该view可以指定界面上的一个控件以高亮的形式突出显示(阴影和圆圈配合),ShowTipsView是Android高亮显示Tips视图,可用于在Andorid应用中高亮显示感兴趣的地方,起到提醒用户的作用。一个Tips...

    android-tips-tricks:[备忘单] Android开发的提示和技巧

    有关Android开发的提示和技巧的备忘单。 这是我从各种来源收集到的一组有关Android开发的简单提示和技巧。 它可以帮助我指导社区中的其他android开发人员有关每个android开发人员应了解的知识。...

    Android代码-Android-RecyclerViewHelper

    方便快捷的 RecyclerView 工具类,支持添加自定义的 header,footer 布局,加载 tips,分页加载。 使用 导入lib-RecyclerViewHelper 具体实现 //使用helper实现分页加载和加载的Tips recyclerViewHelper = new ...

    Android代码-一个用于展示注册进度的view

    &gt; 收集Android你不知道的那些小技巧:https://github.com/jiang111/awesome-android-tips &gt; 收集Android studio 常用的插件,请看这里:https://github.com/jiang111/awesome-androidstudio-plugins &gt; 收集程序员必备的...

    geoguessr-tips:GeoGuessr的提示和资源

    Google Street View的覆盖范围 GeoGuessr的 一些国家的街景区域非常有限。 它可以减少搜索城市名称或道路编号的位置,还可以改善随机猜测。 约旦 突尼斯 突尼斯是东海岸唯一可见的街道 奈及利亚 玻利维亚 德国 德国...

    android布局精解

    本文的主要内容就是分别介绍以上视图的七种布局显示方式效果...• 5、列表视图(List View) o 5.1、一个小的改进 o 5.2、补充说明 • 6、网格视图(Grid View) • 7 、绝对布局() • 8、标签布局(Tab Layout)

    最新图片在线加水印小程序源码亲测可用

    小程序前端源码无需后端直接导入...icon" src="../../static/share.png"&gt;&lt;/image&gt;&lt;/button&gt;&lt;/view&gt;&lt;/top-nav&gt;&lt;view class="u-flex-col"&gt;&lt;add-tips vue-id="8dd740cc-2" duration="300" bind:__l="__l"&gt;&lt;/add-tips&gt;

    Android布局.rar

    我们对Android 应用程序运行原理及布局文件可谓有了比较深刻...• 5、列表视图(List View) o 5.1、一个小的改进 o 5.2、补充说明 • 6、网格视图(Grid View) • 7、绝对布局() • 8、标签布局(Tab Layout)

    Pro iPhone Development with Swift 5, 2nd Edition.pdf

    selling Beginning iPhone Development with Swift, you’ll learn tips for organizing and debugging Swift code, using multi-threaded programming with Grand Central Dispatch, passing data between view ...

    ios-Auto Layout中Stack View的使用.zip

    Stack View提供了一种轻松的方式来使用Auto Layout,github.com/pro648/BasicDemos-iOS 不需要引入复杂的约束。github.com/pro648/tips/wiki 单个堆栈视图定义用户界面的行或列,堆栈视图根据以下属性来排列其子视图...

    AlphaControls v11.13 Stable Full Source (D5~XE10.1) (x86&x64)

    Manager prompts controls the tips in the application and gives them a beautiful view with a lot of settings that can be changed by a special designer. Analogs of standard components provide all the ...

    (0053)-iOS/iPhone/iPAD/iPod源代码-弹出视图(Popup View)-PopTip View

    实现各种弹出消息/tips的效果。点击任意控件,按钮,导航条按钮,工具条按钮(UIBarButtonItem),都会弹出消息气泡。弹出的气泡会自动定位在相应的按钮旁边,并且有小箭头指向这个按钮。气泡的文字和颜色可以自定义...

    Eclipse中文使用教程

    2 .12 快速视图 (Fast View ) 2 .13 比较 2 .14 历史纪录 2 .15 回应 UI 3 .喜好设定 (Preferences ) 3 .1工作台 ( Workbench ) 3.2 Ant 3 .3建置次序 ( Build Order ) 3 .4说明 ( Help ) 3 .5自动更新 ( Install/ ...

    微信小程序跳H5页面

    主页面:index.wxml ...tips: 1.首先,web-view组件的属性src,正如你说看到的,这个就是设置网页链接的,但是需要特别注意的是web-view的src必须配置https协议的链接; 2.其次,就是web-view组件只

    plug-In PHP- 100 Power Solutions

    View Chat; Send Tweet; Send Direct Tweet; Get Tweets; Replace Smileys; Replace SMS Talk; Add User to DB; Get User from DB; Verify User in DB; Sanitize String; Create Session; Open Session; Close ...

    iOS 人机交互指南(iOS Human Interface Guidelines)

    Tips for Creating Great Artwork for the Retina Display 153 Tips for Creating Resizable Images 154 Application Icons 155 Launch Images 157 Small Icons 159 Document Icons 160 Document Icon ...

Global site tag (gtag.js) - Google Analytics