2012-12-05 1 views
0

저는 Task Management System을 구축 중이며 거기에 fullcalendar.js를 구현했습니다. 보류중인 작업을 가져와 대기중인 작업의 색을 변경해야합니다. 레일즈 컨트롤러에서 보류중인 태스크 세부 사항의 인스턴스 변수를 얻고 있습니다. 그러나 아약스 요청에서 나는 그것을 반복 할 수 없다.아약스에서 레일스 인스턴스 변수를 액세스하고 루프합니다.

아래 코드를 찾으십시오.

$('.task_name').live('click', function() { 
    alert(this.id); 
    $.ajax({ 
     url: 'pending_task_details', 
     data: { 
      task_id: this.id 
     }, 
     success: function (data, response, event, date) { <% 
      for date_cell in @[email protected]_tasks.end_date %> getCellFromDate(date_cell, calInstance); <% end %> 
     } 
    }); 
}); 

위의 내용은 구현해야하는 논리입니다. 그러나 나는보기에서 @ pending_tasks.start_date를 얻지 못하고있다. 내가 작업을 얻고 콘솔에서

나는대로 보류중인 작업을 얻고 작업 컨트롤러에서

을 자세히 설명합니다.

def pending_task_details 
    @pending_tasks = Task.find_by_id(params[:task_id]) 
    p "The pending tasks are......",@pending_tasks.inspect 
#(Date.parse(@pending_tasks.start_date.to_s)..Date.parse(@pending_tasks.end_date.to_s)).each { |date| render :json=>[date.strftime('%a %d %b %Y')] and return} 
    render :nothing=>true 
    end 

답변

0

난 당신이 AJAX를 사용하기 때문에 자바 스크립트 파일 (당신의 루비 코드가 전체 페이지가 처음 요청 될 경우에만 실행됩니다) 한 번만 생성됩니다 때문에 오류라고 생각합니다. (!이 작업을 예를)

이 예제를 다운로드 시도하고이 어떻게하는지 확인 :

기본적으로

https://github.com/bokmann/rails3_fullcalendar

할 수 있습니다, 대신이 갖는 :

$.ajax(...) 
...for date_cell in @[email protected]_tasks.end_date 

이 유무 :

$.read(
    '/tasks/54', 
    function (response) { 
    // do something with task here 
    } 
); 
// => [GET] /tasks/54 

체크 아웃 this bokmann이 rails3-fullcalendar 예제에서 사용하고있는 jQuery REST 플러그인.

관련 문제