Rails记得上一页的选择

时间:2015-08-18 11:50:18

标签: ruby-on-rails ruby

这是我的index.html.erb

com.MyCustomStuff 1.0

YourContainer {
    id: container

    // your code

    function createButton() {
        var bt = buttonComponent.createObject(container);
        // do whatever you want from now on :-)
    }

    Component {
        id: buttonComponent
        Button { }
    }
}

页面控制器

 <ul>
  <li><a href="#list1">Question 1</a>
      <div id="list1">Answer </div>
  </li>
  <li><a href="#list2">Question 2</a>
      <div id="list2">Answer </div>
  </li>
  <li><a href="#list3">Question 3</a>
      <div id="list3">Answer </div>
  </li>
  <li><a href="#list4">Question 4</a>
      <div id="list4">Answer </div>
  </li>
  <li><a href="#list5">Question 5</a>
      <div id="list5">Answer </div>
  </li>
  <li><a href="#list6">Question 6</a>
      <div id="list6">Answer </div>
  </li>
</ul>
<%= link_to "Next", pages_feedback_path%>

您好我在尝试使用Ruby on Rails创建网站,用户可以根据自己的选择选择一些项目并获得反馈。

因此,例如,如果用户选择list1和list4并单击下一步,则应将用户带到反馈页面。它应该向用户说明,因为您选择了list1和list4,您可能想尝试这样做。 任何帮助将不胜感激。谢谢你们

1 个答案:

答案 0 :(得分:1)

尝试下面的jQuery -

$('li a').click(function(){
  var next_url = $('a#Next').attr('href');
  if(next_url.match(/?/)){
    $('ul')next('a').attr('href', next_url + '&' + $(this).text() + '=true' )  
  }else{
    $('ul').next('a').attr('href', next_url + '?' + $(this).text() + '=true' )
  }
});

如果没有javascript和html,您可以将表单提交到以下网址 -

<%= form_tag url: pages_feedback_path, method: :get do  %>
  <ul>
    <li><%= check_box_tag 'Question 1' %> Question 1
        <div id="list1">Answer </div>
    </li>
    <li><%= check_box_tag 'Question 2' %> Question 2
        <div id="list2">Answer </div>
    </li>
    <li><%= check_box_tag 'Question 3' %> Question 3
        <div id="list3">Answer </div>
    </li>
    <li><%= check_box_tag 'Question 4' %> Question 4
        <div id="list4">Answer </div>
    </li>
    <li><%= check_box_tag 'Question 5' %> Question 5
        <div id="list5">Answer </div>
    </li>
    <li><%= check_box_tag 'Question 6' %> Question 6
        <div id="list6">Answer </div>
    </li>
  </ul>
  <%= submit_tag('Next') %>
<% end %>