Action Controller知識總覽
Action Controller Overview
Action Controller is the C in MVC. After routing has determined which controller to use for a request, your controller is responsible for making sense of the request and producing the appropriate output.
官方文檔
- controler和action
- 如何用Rails的指令建立controller
- controller的命名規則
- 如何從log中找到對應的controller和action
- params
- params中包含了那些資訊
- params.require, strong params, attr_accessible
- 為什麼會有 Strong Parameters的存在
- session, flash 和 cookies
- session有哪幾種存儲方式,我們項目中用的哪一種?
- session的配置
- session的增删改查
- flash和session的差別
- cookies的增删改查
- cookies, session, flash的使用場景的差別
- filters
- 基本的filter: before_filter, after_filter, around_filter
- 參數 only, except
- Rails如何使用authenticity_token來防止CSRF攻擊
- request和response
- request對象和response對象的生命周期是怎麼樣的, 可以在哪些地方調用
- request.referer, request.method等
- Log Filtering
- 如何設定敏感參數(密碼等)在log中不可見
- render, redirect_to和respond_to
- 如何導出檔案(send_data), 如何下載下傳已經存在的檔案(send_file)
路由部分
The Rails router recognizes URLs and dispatches them to a controller’s action. It can also generate paths and URLs, avoiding the need to hardcode strings in your views.
官方文檔
- resources在config/routes.rb的使用
- 使用resources方法生成了哪些路由?
- resources的參數 only: , except:
- 通過
可看到所有的路由, 該指令輸出的每一列代表什麼?rake routes
- 通過resource可以得到哪些可以使用的path?
- 具名路由(Routes with Namespaces)
- 聲明嵌套路由(Nested Resources), 嵌套路由的使用場景是什麼?
- 添加RESTful風格的路由, member, collection的使用
- member和collection是按照什麼樣的規則生成路由?
- 自定義路由, 如
get 'profile', to: 'users#show'