Essentail Rails Design Pattern

Write Good Rails Code

類似的 Code 在同一個 Controller 出現第3次請注意

場景

#TODO

使用 before_filter 整理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class PostController < ApplicationController
  before_filter :find_category

  def show
    # xxxx
  end

  def edit
    # xxxx
  end

  protected

    def find_category
      @category = Category.find(params[:category_id])
    end
end

Comments