English 中文(简体)
铁路3.1 便携式发动机 HTTP 404 Error on ajax post calls
原标题:rails 3.1 mountable engines HTTP 404 Error on ajax post call

我正在建造我的第一个铁路3.1发动机,其中我有控制器称为举措。 如果我试图通过jquery ajax的“后台”把行动上载起来,那么控制员的行动就知道是上载的。 rb 因为它使用铁路方面的工作3.0

我的路线。

Marcal::Engine.routes.draw do
   resources :media
   resources :initiatives
   post "initiatives/upload"
end

My initiatives_controller.rb

class InitiativesController < ApplicationController
   def upload
     puts "hiiiii"
     @medium = Medium.new(params[:medium])
     if @medium.save
        render :json => {  status  =>  success  }
     else
        render :json => {  status  =>  error  }
     end
  end

end end

And i used do ajax call as below

          $.ajax({
            url: "/initiatives/upload",
            type: "POST",
            data: "medium=something"
            dataType: "json",
            success: function(sucessdata)
            {
              alert("success");
            }

         });      

end

问题回答

你的 du子可能装在“/马尔加”上,这是你创建可移动的发动机时所缺的。 您也许会仅作少量工作,因为寄出关于“<>/initiatives/upload的POST,而不是希望的“/marcal/initiatives/upload

您不妨从“姓名.js”改为“姓名.js.erb”,将其内容改为:

$.ajax({
  url: "<%= root_path %>initiatives/upload",
  type: "POST",
  data: "medium=something"
  dataType: "json",
  success: function(sucessdata)
  {
    alert("success");
  }
});

根基是这里的关键。





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签