将操作传递给控制器自定义控制器方法 - ROR
Pass action to controller custom controller method - ROR
如何将用户正在执行的操作传递给控制器中的方法?
例如:
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
是params[:action]
你想要的吗?
flash[:alert] = "You must log in before you are able to #{params[:action]} foo"
params[:controller]
也应该可用
如何将用户正在执行的操作传递给控制器中的方法?
例如:
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
是params[:action]
你想要的吗?
flash[:alert] = "You must log in before you are able to #{params[:action]} foo"
params[:controller]
也应该可用