i am trying to update a div using form_for :remote => true, but its not happening. given below is my code
<%= 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
PS : 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.
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| %>
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.