Rendering a view of controller action from around_action callback

◇◆丶佛笑我妖孽 提交于 2019-12-05 13:55:15

Okay so with your stack trace it is pretty clear what is happening. You have to understand the default rails behavior of convention over configuration.

As soon as you call yield, your controller action gets called. Now all controller actions by default look to render views with the same name as action, once the actions are done executing.

So calling render_to after yield doesn't make any sense, as controller action you yielded to has already called its render :)

In any case what you are trying to do is a bad design pattern, rendering views should be left to actions

Update

Theoretically speaking : As you wish to keep things DRY you could render the same view after each action by creating a common method calling it after every action. However, think about it, your render will have one line, and calling that same method will need one line too :) so where's the DRY.

In short, DRY should not be over done at the cost of simplicity. In my opinion KISS trumps DRY :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!