anil.n
anil.n

Reputation: 519

406 Not acceptable error while using form_for :remote => true using jquery in rails 3

i am trying to update a div using form_for :remote => true, but its not happening. given below is my code

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>

and this is my controller

  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

P.S : the request is going to controller as html whereas it has to be JS

the product_report.js.erb

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

My actual problem is the div is not getting uploaded. help me out. Thanks in advance.

Upvotes: 1

Views: 1103

Answers (2)

anil.n
anil.n

Reputation: 519

finally i fixed it.

though i was using jquery i had not updated the "rails.js" file, it was still using prototype's "rails.js" file. so the div was not getting updated.

Upvotes: 0

htanata
htanata

Reputation: 36954

In the form_for part, you can use :format => :js as parameter on the :url path to request the JavaScript version of the product_report action.

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

Upvotes: 1

Related Questions