문제

Paginated Model의 인덱스의 각 페이지를 순환하고 싶습니다. jQuery를 사용하여 페이지를 순환합니다. wind_to 표현식이 jQuery가 호출 할 때 생성 조치를 호출하고 있음을 알게됩니다. Link_to 표현식은 다른 상황에서 인덱스 조치를 호출합니다.

예를 들어:

<div id="links">
  <% 1.upto(@total_pages) do |number|%>
    <%= link_to 'Page',"#{clients_path}?page=#{number}" %> 
    <br />
  <% end %>
</div>

기본 라우팅 (예 : Map.Resources : Clients)에서 기대할 수있는 것처럼 인덱스 작업을 호출하는 링크를 생성합니다.

페이지를 순환하려면 다음 HTML이 있습니다.

<div id="show" style="display: none">
    <% 1.upto(@total_pages) do |number|%>
      <%= link_to 'Page#{number}',"#{clients_path}?page=#{number}" %> 
    <% end %>
</div>
<a id="stop" href="#" onclick="stop()">stop</a>
<a id="start" href="#" onclick="start()" style="display: none">start</a>
<div id="output"></div>

그리고 여기 jQuery가 있습니다.

var cur = 0;
var links = [];
var timeout;

function nextLink() {
    if (cur + 1 >= links.length) {
        cur = 0;
    } else {
        cur++;
    }
    return links[cur];
}

function nextPage() {
    $.post(nextLink(), function(data) {
        $("#output").fadeOut("slow", function(){
            $("#output").html(data);
            $("#output").fadeIn("slow");
        });
    });
}

function stop() {
    clearTimeout(t);
    $("#stop").hide();
    $("#start").show();
}

function start() {
    $("#start").hide();
    $("#stop").show();
    slideshow();
}

function slideshow() {
    nextPage();
    t = setTimeout("slideshow()", 5000);
}

$(document).ready(function() {
    $("#show").children().each(function() {
        links.push(this);
    });

    slideshow();
});

이것의 결과 조치는 생성을위한 요청입니다. 내가 무엇을 놓치고 있습니까?

도움이 되었습니까?

해결책

URL에 $ .post (...)에 게시하고 있기 때문에 발생합니다. Rails는 포스트를보고 매핑 된 자원 마법으로 처리하려고합니다. 그것을 $ .get (...)로 변경하면 괜찮을 것입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top