【发布时间】:2014-11-15 21:08:28
【问题描述】:
我正在尝试构建一个自定义控制器操作,该操作将从与控制器相关的咖啡脚本文件中的 ajax 接收参数。
但是控制台提示错误 404 并且无法访问该路由:
如何配置它以使路由和操作正常工作?
对campaigns_controller 的控制器操作:
def create_campaign_location_relationship
@location = Location.find(params[:location_id])
@campaign = Campaign.find(params[:id])
@insert = CampaignLocation.new(campaign_id: @campaign.id,
location_id: @location.id)
@insert.save
end
campaign.js 中的 ajax
$('[name=commit]').bind "click", ->
# Insert the code to allow for a user to
alert "Relationships created"
selectedLocations = root.table.rows(".selected").data()
for locationSelected in selectedLocations
location_id = locationSelected[0]
$.ajax({
url: "create_campaign_location_relationship/" + location_id,
type: "post",
dataType: "json"
})
return
活动路线:
resources :campaigns, only: [:create, :edit, :update, :destroy, :show]
resources :campaigns do
member do
match "/create_campaign_location_relationship/:location_id", to: "campaigns#create_campaign_location_relationship", via: 'post'
end
end
【问题讨论】:
标签: jquery ruby-on-rails ajax routes