rails access view name inside partial

后端 未结 4 1118
梦谈多话
梦谈多话 2021-02-19 12:57

I have a partial that I am using in different pages. I want to conditionally hide a certain div inside the partial based on the view that is rendering it.

I was thinkin

4条回答
  •  灰色年华
    2021-02-19 13:07

    While @wahaj's answer would work, if you want to do what you need in a central location, you could check the controller_name and action_name variables in the partial to determine the view you're in (e.g. controller_name == "services" and action_name == "show" would let you know you're in the Show view for the Service controller)

提交回复
热议问题