Rails ujs(unobtrusive javascript)主要用于ajax吗?
我对 Rails 世界相当陌生。我喜欢 Rails ujs 的概念,因为它使删除、链接和 Ajax 表单的工作变得轻松且不那么混乱。
我想知道是否有处理其他 javascript 函数的正确方法。现在我把这些塞到了 asset 文件夹中的 custom.js 的 document.ready 下。我使用链轮加载此文件。
但这不允许(至少据我所知)使用 <%= escape_javascript .... %>与服务器端对象交错的类型。这是正确的吗?有没有办法让 .js.erb 文件不链接到特定操作?我研究了一种方法,该方法本质上涉及在模型上使用虚拟属性和 html 中的隐藏文本字段。但我对如何解决这个问题保持开放的态度。
如何处理与操作方法不直接相关但需要服务器端信息的 JavaScript 代码?与将其填充到 custom.js 中并使用隐藏变量传递服务器端值相比,是否有更好的方法?
谢谢, 塔布雷兹
I am fairly new to the rails world. I love the rails ujs concept as it makes life easy and less messy for deletes, links and ajax forms.
I am wondering if there is a proper way of dealing with other javascript functions. right now I have these stuffed under document.ready in custom.js in the assets folder. I get this file loaded using sprockets.
But this does not (at least to my knowledge) allow the use of <%= escape_javascript .... %> types of interlacing with server-side objects. Is that correct? Is there a way to have .js.erb files that are not linked to particular actions? I have looked at one approach that essentially involves use of virtual properties on the model and hidden text fields in html. But I am keeping an open mind on how to approach this.
How do you handle javascript code that does not relate directly with the action methods but requires information from the server-side? Is there a better way compare to stuffing it into custom.js and using hidden variables to pass server-side values?
Thanks,
Tabrez
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论