AJAX要求部分采取行动吗? [英] AJAX calls action for a partial?

查看:37
本文介绍了AJAX要求部分采取行动吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个show.html.erb页面,带有相应的动作"show".在页面下方,部分加载了_filter.html.erb,其中包含未定义的实例(因此,基本上,在初始加载时,该位置不显示任何内容).

I have a page show.html.erb with a corresponding action 'show'. Lower on the page, a partial is loaded called _filter.html.erb which contains undefined instances (so basically, on the initial load, nothing is displayed there).

在show.html.erb中,我有一个使用AJAX并提交给名为过滤器"的操作的表单,该操作应该创建一些实例以供_filter部分使用(因此,现在show中的_filter部分将有一些内容).

In the show.html.erb, I have a form that uses AJAX and submits to an action called "filter" which is supposed to create some instances for use within the _filter partial (so now, the _filter partial within show will have some content).

但是当我提交表单时,它说模板丢失缺少模板结果/过滤器.

But when i submit the form, it says Template is missing Missing template results/filter.

但是它应该做的是保留在相同的当前模板(show.html.erb)上,然后运行filter动作并更新部分_fitler.

But what it should be doing is staying on the same current template (show.html.erb) and just run the filter action and update the partial _fitler.

有什么建议吗?

更新

在网上找到了一些东西之后,我创建了一个_filter.js.erb文件,其中包含views/results目录(与show.html.erb和_filter.html.erb相同的目录):

Following some things i found online, i made a file _filter.js.erb withing the views/results directory (same dir as show.html.erb and _filter.html.erb):

$("filter").update("<%= escape_javascript(render("filter"))%>");

但是它似乎没有任何作用..

But it doesnt seem to be doing anything..

推荐答案

如果使用名称 _filter ,请遵循rails约定,然后将此文件放置在 shared 文件夹中.

By rails convention if you use the name _filter then you should put this file in shared folder.

因此应为 shared/_filter.html.erb

这篇关于AJAX要求部分采取行动吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆