rails 5中不再有remote_function
。如何用JavaScript替换它。
我想将旧版rails应用程序升级到5,我陷入了这个(remote_function)的错误
这是我的观点
<p><label for="comment">Special position: </label><%= f.text_field :special_position , :class=>"form-control" %></p>
<p><label for="medium">Medium: </label><%= collection_select(:order_item, :medium_id, @media, :id, :label, { :always_prompt => "Select a medium" }, { :onchange => "#{remote_function(:url => { :action => "medium_changed" }, :with => "'order_item_id=#{@order_item.id}&order_id=#{@order_item.order.id}&medium_id='+value") }", :id => "order_item_medium_id", :name => "order_item[medium_id]" ,:class=>"form-control"} ) %></p>
<p><label for="listing_entry">Listing entry: </label><%= collection_select(:order_item, :contact_id, @listing_entries, :id, :fancy_name, { :always_prompt => "Select a listing entry" }, { :id => "order_item_contact_id", :name => "order_item[contact_id]" ,:class=>"form-control"} ) %></p>
这是控制器中的动作(order_item_controller)
def medium_changed
if !params[:order_item_id].blank?
@order_item = OrderItem.find(params[:order_item_id])
@order_item.medium = Medium.find(params[:medium_id])
else
@medium = Medium.find(params[:medium_id])
end
unless params[:order_id].blank?
@order = Order.find(params[:order_id])
end
render :update do |page|
page.replace_html 'product', :partial => 'product', :locals => { :order_item => @order_item, :medium => @medium, :order => @order }
page.replace_html 'reference', :partial => 'reference', :locals => { :order_item => @order_item, :medium => @medium, :order => @order }
page.replace_html 'category', :partial => 'category', :locals => { :order_item => @order_item, :medium => @medium, :order => @order }
page.replace_html 'region', :partial => 'region', :locals => { :order_item => @order_item, :medium => @medium, :order => @order }
page.replace_html 'city', :partial => 'city', :locals => { :order_item => @order_item, :medium => @medium, :order => @order }
end
end