Ajax Rails路由500内部服务器错误

时间:2015-03-24 00:40:45

标签: ruby-on-rails ajax coffeescript routes internal-server-error

我在广告系列控制器中创建了自定义导轨操作,以便在点击按钮时从ajax调用。但是,单击按钮500时出现服务器错误。

如何缓解500个服务器错误?

错误日志: enter image description here

路线:

  match "/create_campaign_location_relationship/:location_id/:campaign_id", to: "campaigns#create_campaign_location_relationship", via: 'post'

  match "/delete_campaign_location_relationship/:location_id/:campaign_id", to: "campaigns#delete_campaign_location_relationship", via: 'delete'

campaigns.js.coffee:     for newLocations中的aNewLocation

  location_id = aNewLocation
  $.ajax({
    url: "/create_campaign_location_relationship/" + location_id + "/" + campaign_id,  
    type: "post",
    dataType: "json"
  })

for aRemovedLocation in removedLocations

  if aRemovedLocation != 0
    location_id = aRemovedLocation

    # Removing no longer selected locations
    $.ajax({
      url: "/delete_campaign_location_relationship/" + location_id + "/" + campaign_id,  
      type: "delete",
      dataType: "json"
    })

return

广告系列控制器:

def create_campaign_location_relationship
        @location = Location.find(params[:location_id])
        @campaign = Campaign.find(params[:campaign_id])

        @insert = CampaignLocation.new(campaign_id: @campaign.id,
                                       location_id: @location.id)
        @insert.save

    end

    def delete_campaign_location_relationship
        @location = Location.find(params[:location_id])
        @campaign = Campaign.find(params[:campaign_id])

        CampaignLocation.where(campaign_id: @campaign.id, location_id: @location.id).destroy_all
    end

rake路线的结果:

POST   /create_campaign_location_relationship/:location_id/:campaign_id(.:format)                         campaigns#create_campaign_location_relationship

DELETE /delete_campaign_location_relationship/:location_id/:campaign_id(.:format)                         campaigns#delete_campaign_location_relationship

           campaigns POST   /campaigns(.:format)
                                               campaigns#create
       edit_campaign GET    /campaigns/:id/edit(.:format)
                                               campaigns#edit
            campaign GET    /campaigns/:id(.:format)
                                               campaigns#show
                     PATCH  /campaigns/:id(.:format)
                                               campaigns#update
                     PUT    /campaigns/:id(.:format)
                                               campaigns#update
                     DELETE /campaigns/:id(.:format)
                                               campaigns#destroy
         restaurants POST   /restaurants(.:format)

0 个答案:

没有答案