将对象从视图传递给控制器 [英] Passing object from view to controller

查看:188
本文介绍了将对象从视图传递给控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将一个对象,特别是一个视图中使用的form_builder对象传递给控制器​​中的一个动作?我正在使用link_to_remote并想要更新控制器中的变量,然后通过render:update块向我的表单添加新的嵌套表单元素。

如果我将它作为参数传递,它将获得转换后的字符串,而且我似乎也无法成功将局部哈希传递给控制器​​。

解决方案

不,您无法将视图中的对象传递给控制器​​。

所有的逻辑都应该发生在控制器和模型中,并且在过程结束时,视图会将结果呈现在浏览器或其他地方。


Is there a way to pass a object, specifically a form_builder object used in a view, to an action in the controller? I am using a link_to_remote and want to update a variable in the controller and then add a new nested form element to my form via a render :update block.

If I pass it as a param, it gets converted string and I can't seem to successfully pass a locals hash to the controller either.

解决方案

No, you cannot pass an object from the view to the controller.

All your logic should happen in the controller and model and at the end of the process the view renders the result in the browser or other places.

这篇关于将对象从视图传递给控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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