Created
March 9, 2012 17:31
-
-
Save mudge/2007669 to your computer and use it in GitHub Desktop.
Are filters abused in Rails?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyController < ApplicationController | |
def show | |
@model = load_model | |
end | |
def edit | |
@model = load_model | |
end | |
private | |
def load_model | |
Model.find(params[:id]) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyController < ApplicationController | |
before_filter :load_model, :only => [:show, :edit, :update, :destroy] | |
def show | |
end | |
def edit | |
end | |
private | |
def load_model | |
@model = Model.find(params[:id]) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyController < ApplicationController | |
helper_method :model | |
def show | |
# Use +model+ freely | |
end | |
def edit | |
# Use +model+ freely | |
end | |
private | |
def model | |
@model ||= Model.find(params[:id]) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyController < ApplicationController | |
def show | |
load_model | |
end | |
def edit | |
load_model | |
end | |
private | |
def load_model | |
@model = Model.find(params[:id]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The issue is how would you deal with global data. Like menu/cart etc if not using before filter