2011-10-05 56 views
1

我正嘗試使用form_for:remote => true更新div,但沒有發生。下面給出的是我的代碼406在使用form_for時,不可接受的錯誤:remote => true在rails中使用jquery 3

monhtly_report.html.erb

<%= form_for(:monthly_detail, :url => product_report_monthly_details_path,:remote => true) do |f|%> 
<table class="form-table"> 
<tr> 
    <td width="80px"> 
    Product 
    </td> 
    <td colspan="2"> 
    <%= f.collection_select(:product_id, @products, :id,:name, :prompt => true)%> 
    </td> 
</tr> 
<tr> 
    <td> 
    Month 
    </td> 
    <td> 
    <%= select_month(Date.today, :field_name => 'selected_month') %> 
    <%= select_year(Date.today, :start_year => 2000, :end_year => 2020, :field_name =>'selected_year') %> 
    </td> 
</tr> 
<tr> 
    <td></td> 
    <td> 
    <%=submit_button_tag 'Submit'%> 
    </td> 
</tr> 
</table> 
<%end%> 
<div class="monthlyreportsection"> 

</div> 

,這是我的控制器

def product_report 
    @details = MonthlyDetail.find_by_product_id(params[:monthly_detail][:product_id].to_i) 
    @time = Date.new(params[:date][:selected_year].to_i, params[:date][:selected_month].to_i,1) 
    respond_to do |format| 
     format.js 
    end 
    end 

PS:請求將控制器作爲HTML,而它必須是JS

the product_report.js.erb

$("#monthlyreportsection").html("<%=escape_javascript(render(:partial => "product_details"))%>") 

我的實際問題是div沒有上傳。幫幫我。提前致謝。

回答

0

終於我修好了。

儘管我使用的是jquery,但我還沒有更新「rails.js」文件,它仍然使用原型的「rails.js」文件。所以該div沒有得到更新。

1

form_for部分,您可以使用:format => :js作爲:url路徑上的參數來請求product_report操作的JavaScript版本。

<%= form_for(:monthly_detail, 
     :url => product_report_monthly_details_path(:format => :js), 
     :remote => true) do |f| %> 
相關問題