Controller action for partials

戏子无情 提交于 2020-01-17 04:14:05

问题


I was trying to create an action for one of the partials in my rails application, but wondered how to name it. Does it have the underscore at the beginning? Like:

def _my_partial

end

or no underscore? Not mentioned in the controllers guide


回答1:


A partial is a piece of view which is embedded in the main view or within another partial. The purpose of a partial is typically for re-use or to making view code cleaner.

If you need to use an action to render a partial, then it's probably better to either:

  • make your partial into a view, or
  • create a view to embed your partial. See Rails 4 - passing variable to partial


来源:https://stackoverflow.com/questions/28268659/controller-action-for-partials

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