2017-03-13 117 views
1

如何将用户正在采取的操作传递给控制器​​中的方法?将动作传递给控制器​​自定义控制器方法 - ROR

例如:

before_action :require_login, only: [:new, :create, :edit, :update, :destroy] 

如果用户尝试使用:编辑动作在我的方法在登录之前,我想说的是这样的:

def require_login 
    unless current_user 
    if (:edit action) 
     flash[:alert] = "You must log in before you are able to edit foo" 
    end 
    end 
end 

回答

1

params[:action]你'之后?

flash[:alert] = "You must log in before you are able to #{params[:action]} foo" 

params[:controller]应该可以过