我有以下路线,当我执行“耙路线”时,它会出现在列表中:
page_upload_image POST /pages/:page_id/upload_image(.:format) pages#upload_image
我的路由文件中还有以下内容:
resources :pages do
post :sort, :on => :collection
post :upload_image, :on => :collection
end
然后,我使用 JavaScript 来捕获并发布从以下内容中提取的值:
%form.new-page-image{:class => "hide", :action => "/pages/#{@page.id}/upload_image"}
%input.page_image{:type => "file", :name => "page[image]", :multiple => "true"}
我的页面控制器中的 upload_image 操作有以下内容:
def upload_image
image = params[:page][:image]
uploader = PageImageUploader.new
uploader.store!(image)
render json: uploader.to_json
end
出于某种原因,即使路线存在,当我发布到它时,我也会得到以下信息:
ActionController::RoutingError (No route matches [POST] "/pages/1/upload_image"):
我想知道为什么一个看起来合法的路由(在执行 rake 路由时正确显示)会在我尝试发布到它时返回此错误。