Ruby on Rails 3.1:“渲染”错误来自 RailsCasts 的 javascrtip (AJAX)(使用 AJAX 进行搜索、排序、分页)
我的代码来自: RailsCasts:使用 AJAX 进行搜索、排序、分页
我遇到此错误:
undefined method render for #<#<Class:0x9e54e54>:0xa860f24>
(in /var/www/final/.../app/assets/javascripts/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;
}); });
在 index.html.erb 中渲染 'zoznam'(_zoznam.html.erb) 可以。 “zoznam/index”是我的带有自定义 SQL 选择的产品列表。一切都好,但“大胆”的剧本不好。 '
My code is from: RailsCasts: Search, Sort, Paginate with 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:
$(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. "zoznam/index" is list of my products with custom sql select. It´s all OK but "bold" script is not good. '
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自TheCompWiz:
原始论坛
好吧...我想我找到了 Rails 3.1 的修复程序。诀窍是避免使用资产。您需要呈现页面。这可能看起来很黑客……我同意……但它确实有效。这可能在未来可以得到更好的完善。
您需要做的是在路由文件中的产品“资源”之前添加一个条目,如下所示:
并照常进行。本质上,它的作用是让 Rails 跳过使用全新的资源管理器系统……并返回到老式的渲染设置。这可能是一件好事,因为 index.js 是根据请求渲染的,不会与其他 javascript 连接在一起,也不会缩小。
//也许是个好答案...
from TheCompWiz:
original forum
Ok... I think I found a fix for 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:
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. 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.
//maybe good answer...