Rails 同一页面与 url 参数仅更改 [英] Rails Same page with url paramaters only change

查看:37
本文介绍了Rails 同一页面与 url 参数仅更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,这是我从 mysql 数据库中获取值的视图,我根据 params page=1 page =2 page =3 在浏览器中显示,我想在表单下一个按钮单击中更改 params[:page].

基于 pages=1,2,3 的问题和答案会有所不同,这就是为什么我需要在同一页面中单击按钮时更改 url.!像下面的网址 http://localhost:3000/responses/new?page=1 提前致谢.

<%= form_for (@response) do |f|%><% @questions.each 做 |pgquestion|%><% 如果 pgquestion.group_id == 0 %><%=标签:pgquest,pgquestion.description %><br><br><%其他%><%=标签:pgquest,pgquestion.description %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% (1..pgquestion.question_value.to_i).每个都做 |i|%><%= radio_button_tag "ans_value[#{ pgquestion.quest_id }]", i %><%结束%><br><br><% if pgquestion.question_type == "textarea" %><%= text_area "", "ans_value[#{ pgquestion.quest_id }]" ,size: '80x5' %><br><br><% else if pgquestion.question_type == "text" %><%= text_field "", "ans_value[#{ pgquestion.quest_id }]" %><br><br><%结束%><%结束%><%结束%><%结束%><div style="text-align: center"><%= f.submit 'Prev' ,:class =>'btn btn-primary',:name =>previous_button"%><%= f.submit 'Next', :class =>'btn btn-primary'%><br><br><p><%= f.submit "Continue" %></p><p><%= f.submit "Back", :name =>"previous_button" %></p>

<%结束%>

解决方案

据我了解您的问题,请使用 will_paginate gem https://github.com/mislav/will_paginate

Actually this is my view am getting values from mysql database and i showed in browser based on the params page=1 page =2 page =3 and i want to change the params[:page] in form next button click.

Based on pages=1,2,3 questions and answers will vary thats why i need url to be change while button click in same page.! like below URL http://localhost:3000/responses/new?page=1 Thanks in advance.

<%= form_for (@response)  do |f| %>
    <% @questions.each do |pgquestion| %>
        <% if pgquestion.group_id == 0 %>
            <%= label :pgquest,pgquestion.description %><br><br>
        <% else %>

            <%= label :pgquest,pgquestion.description %> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            <% (1..pgquestion.question_value.to_i).each do |i| %>
                <%= radio_button_tag "ans_value[#{ pgquestion.quest_id }]", i %>
            <% end %>
            <br><br>
            <% if pgquestion.question_type == "textarea" %>

                <%= text_area "", "ans_value[#{ pgquestion.quest_id }]" ,size: '80x5'  %><br><br>
            <% else if pgquestion.question_type == "text" %>
                    <%= text_field "", "ans_value[#{ pgquestion.quest_id }]"  %>   <br><br>

            <% end %>

            <% end %>

        <% end %>

    <% end %>
      <div style="text-align: center">
    <%= f.submit 'Prev' ,:class => 'btn btn-primary',:name => "previous_button" %>
    <%= f.submit 'Next', :class => 'btn btn-primary' %> <br><br>

        <p><%= f.submit "Continue" %></p>
        <p><%= f.submit "Back", :name => "previous_button" %></p>

      </div>

<% end %>

解决方案

As far as i understand your problem use the will_paginate gem https://github.com/mislav/will_paginate

这篇关于Rails 同一页面与 url 参数仅更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆