01 - passing data from the controller to the view.rb
来自「O Reilly Ruby Cookbook source code」· RB 代码 · 共 49 行
RB
49 行
class NovelController < ApplicationController def index @title = 'Shattered View: A Novel on Rails' one_plus_one = 1 + 1 increment_counter one_plus_one end def helper_method @help_message = "I see you've come to me for help." end private def increment_counter(by) @counter ||= 0 @counter += by endend#---<h1><%= @title %></h1><p>I looked up, but saw only the number <%= @counter %>.</p><p>"What are you doing here?" I asked sharply. "Was it <%=@counter.succ %> who sent you?"</p>#---class NovelController < ApplicationController @@numbers = [1, 2, 3] TITLE = 'Revenge of the Counting Numbers'end#---# config/environment.rbAUTHOR = 'Lucas Carlson'#---<h1><%= @title %></h1><p>by <%= AUTHOR %></p>...#---$one = 1class NovelController < ApplicationController $two = 2 def sequel $three = 3 endend#---Here they come, the counting numbers, <%= $one %>, <%= $two %>, <%= $three %>.#---
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?