简体   繁体   English

在Rails上更新网页的一部分

[英]Updating part of a web page on Rails

I have a Rails controller with a form, and I want that when I post this form, a table on this page is updated via AJAX. 我有一个带有表单的Rails控制器,我希望在发布此表单时通过AJAX更新此页面上的表格。 I know a way, using partials to achieve this, but is that any way to do this without partials? 我知道一种使用局部的方法来实现此目的,但是有没有这种方法的没有局部的方法吗? And without putting code for my view inside my controller too. 而且也没有将我的视图代码放入控制器中。

Thanks 谢谢

You can make a .js.erb file as the view, and from the form call the action from link_to_remote. 您可以将.js.erb文件作为视图,然后从表单中调用link_to_remote的操作。 That will translate into an ajax call to the action, that will then execute the js from the view. 这将转换为对动作的ajax调用,然后将从视图中执行js。 Inside that js.erb file you can do whatever you like. 在该js.erb文件中,您可以执行任何操作。 Although it will be hard to render part of the table server side if the code isn't broken out into a partial. 如果不将代码分解成部分代码,将很难呈现表服务器端的一部分。

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

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