Ajax / rails发布404错误

时间:2012-01-13 19:14:26

标签: ajax ruby-on-rails-3 jquery post

我是AJAX的新手。只是测试要放入我的应用程序的功能,并创建一些代码:

获得此视图(index.html.erb)

  <%= form_for :form, :remote => true, :url => {:action => "index"} do |f| %>
      <input type="hidden" value="No" name="answer">
      <input type="submit" value="No">
  <% end %>

  <%= form_for :form, :remote => true, :url => {:action => "index"} do |f| %>
      <input type="hidden" value="Yes" name="answer">
      <input type="submit" value="Yes" >
  <% end %>

  <div id="answerDiv"></div>

获得此控制器(controller-perguntas.rb)

类ControllerPerguntasController&lt; ApplicationController的     def index

  if params[:answer] == "Yes"
    if PhrasesYes.all != []
      @answer = PhrasesYes.first 
    else
      @answer = "Yes phrase"
    end

  elsif params[:answer] == "No"
    if PhrasesNo.all != []
      @answer = PhrasesNo.first
    else
      @answer = "No phrase"
    end

  elsif params[:answer] == nil
    @answer = "No phrases here"
  end
end

得到这个部分(_answer-text.html.erb)

  <%=@resposta%>

得到了这个javascript(index.js.erb)

  $('#answerDiv').html("<%= escape_javascript(render(:partial => '_answer-text')) %>");

我本来应该点击一些按钮(是或否)并使用对象PhrasesYes或PhrasesNo填充div #answerDiv,具体取决于我点击的按钮。

但每次Chrome检查器脚本日志都会给我这个:

POST http://localhost:3000/controller_perguntas/index 404 (Not Found)
jQuery.ajaxTransport.sendjquery.js:8103
jQuery.extend.ajaxjquery.js:7581
$.rails.rails.ajaxjquery_ujs.js:99
$.rails.rails.handleRemotejquery_ujs.js:154
(anonymous function)jquery_ujs.js:344
jQuery.event.dispatchjquery.js:3257
jQuery.event.add.elemData.handle.eventHandle

有什么不对或缺失???谢谢!

0 个答案:

没有答案