簡體   English   中英

RoR XML API說找不到路由。 手動添加路線沒有幫助。 我究竟做錯了什么?

[英]RoR XML API says route not found. manually adding route doesn't help. What am I doing wrong?

我正在嘗試從終端執行的命令:

curl "http://acme.example.com/controller_name/destroy.xml?api_key=123&id=150&other_id=430"

只是一個簡單的GET請求,沒有什么特別的。

但是當我這樣做時,我得到了這個錯誤:

ActionController::RoutingError 
(No route matches "/controller_name/destroy.xml" with 
{:remote_ip=>"127.0.0.1", 
 :accepts=>"*/*", 
 :protocol=>"http://", 
 :subdomain=>"acme", 
 :method=>:get, 
 :request_uri=>"/controller_name/destroy.xml?api_key=123&id=150&other_id=430", 
 :port=>80, 
 :content_type=>nil, 
 :domain=>"example.com"}):

因此,然后將其添加到我的routes.rb文件中:

  map.connect "/controller_name/destroy", :controller => :controller_name, :action => :destroy

但是我遇到了同樣的錯誤,所以我添加的路由根本沒有幫助。

這是controller_name中的destroy方法

  def destroy
    @other = Other.find(params[:other_id])
    attachment = @other.attachments.find(params[:id])
    attachment.destroy

    @attachments = @other.attachments

    respond_to do |format|
      format.xml do
        head :ok 
      end
    end
  end

在routes.rb中,controller_name只是通過這種方式包含的:

  map.resources :others, :has_many => [:controller_names]

並且控制器中已經存在的所有AJAX內容都可以正常工作...即使對於相同的方法,使用AJAX請求調用destroy也可以....但XML部分不行.....> _ <

看起來您缺少請求的格式。

map.connect "/controller_name/destroy(.:format)", :controller => :controller_name, :action => :destroy

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM