Ruby on Rails: conditionally display a partial

前端 未结 3 683
一个人的身影
一个人的身影 2021-02-11 14:05

I\'m not sure if I\'m doing the best approach here, but I have a block of data that I want to show after a search is done and to not be there at all before. First of all, there

3条回答
  •  走了就别回头了
    2021-02-11 14:51

    One easy way is to use a helper method. Helpers tend to be a bit cleaner than putting logic directly in the view.

    So, your view might be something like :

    <%= render_stuff_conditionally %>
    

    and your helper would have a method to control this:

    def render_stuff_conditionally
      if @contional_check
        render :partial => 'stuff'
      end
    end
    

    where obviously things are named more appropriately

提交回复
热议问题