我今天刚开始学习 ruby,我对以下代码有疑问。我想知道 ":only =>:show" 究竟是如何影响这里的代码的。我假设如果我们没有“:only =>:show”,那么代码将直接处理身份验证。但是 ":only =>:show" 到底是做什么的呢?谢谢!
class PeopleController < ApplicationController
before_filter :authenticate, :only =>:show
def index
@people = ["luke-skywalker", "darth-vader"]
end
def show
@person = params[:id]
end
private
def authenticate
if params[:id] == "darth-vader"
redirect_to people_url, :notice => "The page is restricted."
#this is called the flash message
end
end
end