Rails:如何在控制器中呈现其他动作,在js中不在html中?(Rails : how to render an other action in the controller, in js not

编程入门 行业动态 更新时间:2024-10-19 04:32:28
Rails:如何在控制器中呈现其他动作,在js中不在html中?(Rails : how to render an other action in the controller, in js not in html?)

我的控制器中有两个动作:

def find @item = Item.find(params[:id]) render 'result', :id => @item.id end def result @item = Item.find(params[:id]) respond_to do |format| format.js end end

问题在于我首先调用find动作,然后调用result动作但是采用html格式。 所以'format.js`永远不会被触发。

如何在find操作结束时以js格式呈现result操作?

非常感谢 !

I have two actions in my controller :

def find @item = Item.find(params[:id]) render 'result', :id => @item.id end def result @item = Item.find(params[:id]) respond_to do |format| format.js end end

The issue in that I call first the find action, then it calls the result action but in the html format. So the 'format.js` is never triggered.

How can render, at the end of the find action, the result action in the js format ?

Thanks a lot !

最满意答案

在你的find方法中尝试这个。

render 'result', :id => @item.id, :format => :js

Try this in your find method.

render 'result', :id => @item.id, :format => :js

更多推荐

本文发布于:2023-08-05 20:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437994.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:器中   动作   如何在   Rails   js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!