2012-09-24 54 views
0

我已經在一個div中放置了一個餅圖,並且想通過按網頁上的兩個鏈接(計數或總數)之一來重新計算提供它的數據。無法用Ajax刷新div,我做錯了什麼?

這是我的觀點摘錄:

<%= link_to "Count", {action: "switch_chart_dim"}, remote:true %> 
<%= link_to "Total", retailers_switch_dim_path("total"), remote:true %> 
<div id="visualization" > 
    <%= render partial: '/charts/highcharts_pie', locals: {pie_data: @pie_gender} %> 
</div> 

我的控制器:

def switch_chart_dim(type=:count) 
    logger.debug("URRAY i am here") 
    @pie_gender = Receipt.group_by_gender_pie(current_user, type, 
               params["/retailers"][:begin_date], 
               params["/retailers"][:end_date]) 
    respond_to do |format| 
     format.js { render :layout=>false } 
    end 
end 

我的js文件(switch_chart_dim.js.erb)

$('#visualization').html('<%= escape_javascript(render(:partial: '/charts/highcharts_pie', locals: {pie_data: @pie_gender})).html_safe %>') 

我讀過幾個職位在此,並試圖應用這一切,但由於某種原因,似乎我的控制器行動甚至沒有被稱爲(至少我canno在日誌中看到我的「URRAY」調試消息)。

我在做什麼錯?

編輯

這裏是我匹配的路由,如果它可能是相關的:

match '/retailers', to: 'retailers#switch_chart_dim', via: :post, as: "retailers_switch_dim" 

回答

0

我似乎找到了我的問題與這一個。

我的路線文件有兩條相互衝突的路線,它正在調用搜索操作。我發現這個通過分析在Firebug要求:

match '/retailers', to: 'retailers#search', via: :post, as: "retailers_search" 
match '/retailers', to: 'retailers#switch_chart_dim', via: :post, as: "retailers_switch_dim" 

通過更換

match '/retailers', to: 'retailers#switch_chart_dim', via: :post, as: "retailers_switch_dim" 

match '/retailers/switch_chart_dim', to: 'retailers#switch_chart_dim', via: :post, as: "retailers_switch_dim" 
解決它