发出请求的按钮:
<%= link_to business_domain.name, data_services_fetch_by_business_domain_path(:business_domain_id => business_domain.id, :data_services => @data_services), :remote => true %>
routes.rb中的路由:
get "data_services_fetch_by_business_domain" => 'data_services#fetch_by_business_domain', :as => :data_services_fetch_by_business_domain
控制器方法:
def fetch_by_business_domain
@data_services_for_domain = BusinessDomain.find(params[:business_domain_id]).data_services
params[:data_services] & @data_services_for_domain
respond_to do |format|
format.js { render :action => display_data_service_records.js.erb }
end
end
从控制器方法引用的 display_data_service_records.js.erb
:
$("#data-service-listings").html("<%= escape_javascript(render partial: 'listings', locals: { data_services: @data_services } ) %>");
应该更新的部分:
<div class="well" id="data-service-listings">
...
</div>
上面是否存在错误,或者这种方法是否存在根本错误?感谢。
答案 0 :(得分:1)
如果你看一下你做过的路线
get "data_services_fetch_by_business_domain" => 'data_services#fetch_by_business_domain', :as => :data_services_fetch_by_business_domain
您正在制作包含获取请求的路线,但如果您想发送一些数据,则应使用 发布请求。
将您的网址更改为
post "business_domain/:business_domain_id" => 'data_services#fetch_by_business_domain', :as => :data_services_fetch_by_business_domain
你的link_to看起来像是:
<%= link_to business_domain.name, data_services_fetch_by_business_domain_path(:business_domain_id => business_domain.id, :data_services => @data_services),method: :post, remote: true %>
您可以params[:data_services]
访问data_services数组,params[:bussiness_domain_id]
访问bussiness_domain_id