⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 12 - refactoring code into helper functions.rb

📁 O Reilly Ruby Cookbook source code
💻 RB
字号:
$ ./scripts/generate controller list index      exists  app/controllers/      exists  app/helpers/      create  app/views/list      exists  test/functional/      create  app/controllers/list_controller.rb      create  test/functional/list_controller_test.rb      create  app/helpers/list_helper.rb      create  app/views/list/index.rhtml#---class ListController < ApplicationController  def index    @list = [1, "string", :symbol, ['list']]  endend#---<!-- app/views/list/index.rhtml --><ul><% @list.each_with_index do |item, i| %>  <li class="<%= i%2==0 ? 'even' : 'odd' %>"><%= i %>:     <%= SHA1.new(item.id.to_s) %></li><% end %></ul>#---module ListHelper  def create_li(item, i)    %{<li class="#{ i%2==0 ? 'even' : 'odd' }">#{i}:       #{SHA1.new(item.id.to_s)}</li>}  endend#---<!-- app/views/list/index.rhtml --><ul><% @list.each_with_index do |item, i| %>  <%= create_li(item, i) %><% end %></ul>#---

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -