我想在某些条件下 render 输出文本内容然后结束 action,类似 php 的 die,必须在 render 前加 return 吗?请大侠不吝赐教
试试不就知道了
会往下执行的,除非有 return
感谢大虾赐教,不过我定义了一个用于 before_action 调用的方法,貌似不用 return 也会退出
def only_post_method if request.method != 'POST' render plain: '只允许post提交' end end before_action :only_post_method, :only => [:create, :update]
多查查文档吧 If a "before" filter renders or redirects, the action will not run. If there are additional filters scheduled to run after that filter, they are also cancelled.
http://guides.rubyonrails.org/action_controller_overview.html#filters
感谢大虾指点迷津🙏,看来我在文档阅读上还有欠缺