rails access view name inside partial

后端 未结 4 1092
梦谈多话
梦谈多话 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:15

    simple solution , inside your partial check if you need to show partial or not

    _partial_name.html.erb

    <%= content_tag :div, :style=> "display : #{show_div? ? 'block' : 'none'}" do%>
      html...or other stuff
     <%end%>
    

    and then in application helper

    app/helper/application_helper.rb

    def show_div? #you can set name of your div like 'show_sidebar_div?'
      #decide either show this div or not
     action_name == 'show'
    end
    

提交回复
热议问题