【问题标题】:AJAX + RAILS Problem with ShowTooltip window effect...Routing Error in RailsAJAX + RAILS ShowTooltip 窗口效果问题... Rails 中的路由错误
【发布时间】:2010-02-13 08:05:19
【问题描述】:

AJAX + RAILS 问题。我收到以下路由错误:

<div class="card-field">
  <h6><imgsrc="/images/red_icon.png" width="16" alt="" align="absmiddle" class="image-3"  onmouseover="ajax_showTooltip(window.event,'/quickadd_notes_help.html.erb?ranId='+Math.random(),this,'','');return false;"  /></h6>
 <p>Company Name:</p>
 <input type="text" name="company" id="company" size="50" />
 </div>

ActionController::RoutingError (No route matches "/quickadd_notes_help.html.erb" with {:method=>:post}):

不知道我在这里做错了什么。当我去

时,我的控制器和视图都工作正常
http://localhost:3000/cats
http://localhost:3000/cats/quickadd_notes_help

我尝试过以多种方式修改我的 HTML!

window.event,'/quickadd_notes_help.html.erb?ranId='...
window.event,'/quickadd_notes_help?ranId='...
window.event,'/quickadd_notes_help.html?ranId='...

我有同样的例子在托管的非 Rails 环境中运行良好。但似乎无法让它在 Rails 环境中工作。我的 routes.rb 文件如下所示:

map.resources :cat

感谢您提供的任何帮助!

谢谢, 席德

【问题讨论】:

    标签: javascript ruby-on-rails ajax


    【解决方案1】:

    动作是/quickadd_notes_help,而不是/quickadd_notes_help.html.erb

    <div class="card-field">
      <h6><imgsrc="/images/red_icon.png" width="16" alt="" align="absmiddle" class="image-3"  onmouseover="ajax_showTooltip(window.event,'/quickadd_notes_help?ranId='+Math.random(),this,'','');return false;"  /></h6>
     <p>Company Name:</p>
     <input type="text" name="company" id="company" size="50" />
    </div>
    

    此外,您应该在适用的情况下使用 Rails 帮助程序来生成路径。 假设路由被称为quickadd_notes_help

    <div class="card-field">
      <h6><imgsrc="/images/red_icon.png" width="16" alt="" align="absmiddle" class="image-3"  onmouseover="ajax_showTooltip(window.event,'<%= quickadd_notes_help_path %>?ranId='+Math.random(),this,'','');return false;"  /></h6>
     <p>Company Name:</p>
     <input type="text" name="company" id="company" size="50" />
    </div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-16
      • 1970-01-01
      • 2017-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多