【问题标题】:Problem using link_to with remote option in rails 3在rails 3中使用带有远程选项的link_to时出现问题
【发布时间】:2011-07-05 11:11:20
【问题描述】:

我正在使用带有 link_to 远程选项的 rails 3 工作。

这是我的代码结构。

查看/打孔/report.html.erb:


<%= link_to 'Punch report', punchreport_punch_index_path, :remote => true%>
<div id="punchform"> </div>

查看/punch/punchreport.js.erb:


$("#punchform").html("<%= escape_javascript(render(:partial => "reportform"))%>");

并在里面创建了一个表单

查看/punch/_reportform.html.erb

和控制器:

控制器/punch_controller.rb


def report

end

def punchreport
  respond_to do |format|
   format.html { render report_punch_index_path }
   format.js 
  end
end

注意:punchreport_punch_index_path:/punch/punchreport

    report_punch_index_path     : /punch/report

我没有让 ajax 请求正常工作。相反,它会重定向页面。

任何帮助 在此先感谢

【问题讨论】:

    标签: ajax ruby-on-rails-3


    【解决方案1】:

    听起来你的 :remote => true 没有被一个不显眼的 javascript 事件处理程序处理...

    你的项目中有没有叫做 jquery-rails 的东西?它应该在“数据远程”属性上设置一个处理程序。你能找到它并发回你在那里的东西吗?

    【讨论】:

    • 我使用的是 rails 3.0.9 并且应用程序中包含 rails.js 文件。我得到以下输出:模板丢失缺少模板/punch/punchreport with {:locale=>[:en, :en], :formats=>[:html], :handlers=>[:rxml, :erb, :builder, :rjs, :rhtml]}
    • 包含的文件是: ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "jquery.rails.js" %> ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js' %>
    • 你能在 jquery.rails.js 文件中找到某种“数据远程”吗?你应该有这样的东西: $('a[data-remote],input[data-remote]').live('click', function (e) { $(this).callRemote(); e.preventDefault( ); });
    猜你喜欢
    • 2013-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    相关资源
    最近更新 更多