0
我正在嘗試構建一個自定義控制器操作,它將從控制器相關的coffeescript文件中的ajax接收參數。沒有路由匹配使用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
阿賈克斯在campaigns.js
$('[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
在路由中,我將'get'更改爲'post'和ajax中的更改,我仍然收到控制檯 – Sauron
中的錯誤404,以及錯誤描述是什麼? – blelump
再次出現錯誤404,找不到 – Sauron