简体   繁体   English

Ruby on Rails 3.1:来自RailsCasts的javascrtip(AJAX)中的“渲染”错误(使用AJAX进行搜索,排序,分页)

[英]Ruby on Rails 3.1 : error with “render” in javascrtip (AJAX) from RailsCasts (Search, Sort, Paginate with AJAX)

My code is from: RailsCasts: Search, Sort, Paginate with AJAX 我的代码来自: RailsCasts:使用AJAX搜索,排序,分页

I have this error: 我有这个错误:

undefined method render for #<#<Class:0x9e54e54>:0xa860f24>
(in /var/www/final/.../app/assets/javascripts/application.js.erb)

My application.js.erb: 我的application.js.erb:

$(function() {
 $("#zoznam_render th a, #zoznam_renders .pagination a").live("click", function() {
    $("#zoznam_render").html("**<%=j render 'zoznam' %>**");
    return false;
  }); });

In index.html.erb render 'zoznam'(_zoznam.html.erb) is OK. 在index.html.erb中渲染'zoznam'(_ zoznam.html.erb)可以。 "zoznam/index" is list of my products with custom sql select. “ zoznam / index”是带有自定义sql select的我的产品列表。 It´s all OK but "bold" script is not good. 没关系,但是“粗体”脚本不好。 ' '

from TheCompWiz : original forum Ok... I think I found a fix for rails 3.1. 来自TheCompWiz原始论坛好的...我想我找到了针对Rails 3.1的修复程序。 The trick is to keep from using assets. 诀窍是避免使用资产。 You need the page to be rendered. 您需要呈现页面。 This may seem hack-ish... I agree... but it does work. 这似乎有些破绽...我同意...但是确实可以。 This can probably be better refined in the future. 将来可能会更完善。

What you need to do, is add an entry in the routes file before the "resources" for products like so: 您需要做的是在路由文件中的产品“资源”之前添加一个条目,如下所示:

match "/products/index.js", :controller => 'products', :action => 'index', :format => :js 匹配“ /products/index.js”,:controller =>'products',:action =>'index',:format =>:js

and proceed as normal. 然后照常进行。 What this does in essence is get Rails to skip using the brand-new asset manager system... and go back to the old-fashioned rendering setup. 这实质上是让Rails跳过使用全新的资产管理器系统的操作……并返回老式的渲染设置。 This is probably a good thing as the index.js is rendered per-request and won't be concat'd together with the other javascript and not minified. 这可能是一件好事,因为index.js是按请求呈现的,不会与其他javascript并置在一起并且不会缩小。

//maybe good answer... //也许是个好答案...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM