如何将用户正在执行的操作传递给控制器中的方法?
例如:
before_action :require_login, only: [:new, :create, :edit, :update, :destroy]
如果用户在登录我的方法之前尝试使用:edit操作,我想说出这样的话:
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
答案 0 :(得分:1)
params[:action]
你追求的是什么?
flash[:alert] = "You must log in before you are able to #{params[:action]} foo"
params[:controller]
也应该可用