10 - setting and retrieving session information.rb
来自「O Reilly Ruby Cookbook source code」· RB 代码 · 共 44 行
RB
44 行
class IndexController < ApplicationController def index session[:first_time] ||= Time.now endend#---<!-- index.rhtml -->You first visited this site on <%= session[:first_time] %>. That was <%= time_ago_in_words session[:first_time] %> ago.#---class ApplicationController < ActionController::Base model :user, :ticket, :item, :historyend#---class IndexController < ApplicationController def index session[:user] ||= User.find(params[:id]) endend#---class ApplicationController < ActionController::Base session :offend#---class MyController < ApplicationController session :offend#---class MyController < ApplicationController session :off, :only => ['index'] def index #This action will not have any sessions available to it endend#--- flash[:error] = 'Invalid login.'#---Rails::Initializer.run do |config| config.action_controller.session_store = :active_record_storeend#---
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?