使用RAILS 3.2中的include方法的具有特定内容的当前页面或路由

时间:2013-09-04 07:23:25

标签: ruby-on-rails

嗨,我似乎无法让这项工作在视野中,

if current_page?(question_path).include?("Question 1")

如果当前页面检测到"Question 1"

的文本,我的条件会显示特定的html元素

满足它的最佳方法是什么?

因为,如果我使用具有特定ID的特定路线,那么它甚至不是动态的。

if current_page?(question_path(1))

如果ID:1已被删除,可以更改吗?

Snippet(我现在拥有的):

.reference_display
  .reference_container
    - if current_page?(question_path).include?("Question 1")
      .reference_lip_ref
        .lip_arrow{:title => "Click to expand"} ◀
        .close_btn{:title => "Close"}
        .lip.close_btn{:title => "Close"}
        .slide
          .preloader
          %ul{"data-orbit" => "", "data-options" => "timer_container_class: hide; timer_paused_class: hide; timer_progress_class: hide; timer_speed:240000;"}
            - @question.references.order("my_order").each do |r|
              %li
                %img.referenceImage{:alt => "Reference Data", :src => "#{r.image_url}", :style => "border: 1px solid #ccc;"}/
    - elsif @questions.last
      .reference_lip
        .lip_arrow{:title => "Click to expand"} ◀
        .close_btn{:title => "Close"}
        .lip.close_btn{:title => "Close"}
        .slide
          .preloader
          %ul{"data-orbit" => "", "data-options" => "timer_container_class: hide; timer_paused_class: hide; timer_progress_class: hide; timer_speed:240000;"}
            - @question.references.order("my_order").each do |r|
              %li
                %img.referenceImage{:alt => "Reference Data", :src => "#{r.image_url}", :style => "border: 1px solid #ccc;"}/

1 个答案:

答案 0 :(得分:1)

您可以尝试这样的事情:

- if request.path.include?('suggestion')
  = your code