[英]Adding functionality to a controller with alias_method_chain
我正在使用alias_method_chain向控制器添加功能,但無法訪問參數。 這里params [:email]為nil
module Spree::MyExtensionUsersController
def self.included(target)
target.class_eval do
alias_method_chain :create, :extra
end
end
def create_with_extra
#email comes from a form
email = params[:email]
do_something(email)
create_without_extra
end
end
嘗試使用before_filter
:
def self.included(target)
target.send :before_filter, :do_something_with_email, :only => :create
end
def do_something_with_email
#email comes from a form
email = params[:email]
do_something(email)
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.