2012-09-18 2 views
1

가 어떻게 아약스 함수에서 일부를 호출 할 수 있습니다 AJAX URL 레일에서 부분, 내 home.html.erb 내부 부분의 내용을 렌더링 할 필요가 여기에 코드 :전화가

<div class="span8"> 
    <h3>Micropost Feed</h3> 
    <div class="posts"> 
     <%= render 'feed' %> 
    </div> 
</div> 

나는 스크립트가 하단에서

, 문제의 코드는 다음 줄에 있습니다

if(nearBottomOfPage()) { 
    loading=true; 
    page++; 
    $.ajax({ // send an ajax-request to load the next page 
    url: '/feed?page=' + page, 
    type: 'get', 
    dataType: 'script', 
    success: function() { // after successfully completing the ajax-request redraw the sausage-navigation. 
     $(window).sausage('draw'); 
     loading=false; 
    } 
    }); 

은 "URL"매개 변수가 나는 부분 전화를 쓸 모르는 곳이며,이 부분은 전화 _feed입니다 .html.erb 그리고 그것은 같은 f 안에 있습니다.

def home 
    if signed_in? 
    @post = current_user.posts.build 
    @feed_items = current_user.feed.order(:created_at).page(params[:page]) 
    end 
    respond_to do |format| 
     format.js { render :partial => 'feed'} 
     format.html # index.html.erb 
     format.xml { render :xml => @feed_items } 
    end 
end 

가 어떻게 호출 할 수 아약스 함수의 부분 : 내 컨트롤러 액션에서 마침내, Home.html.erb의 이전 나는이 있나요?

고마워요.

답변

2

부분을 URL을 통해 직접 호출 할 수 없습니다./public 디렉토리의 페이지 /보기 만 직접 액세스 할 수 있습니다.

'피드'부분과 해당 경로를 렌더링하는 컨트롤러 동작을 만들어야합니다. 그런 다음 해당 경로의 경로를 AJAX URL로 사용하십시오.

+0

나는 feed.html.erb에서 필요한 내용을 가지고 있는데 escape_javascript (????)로 어떻게 렌더링 할 수 있습니까? –

관련 문제