我可以从控制器返回值而不是视图吗?

时间:2021-09-24 11:46:21

I would like to return the id of a newly created object for my ajax call instead of returning the view associated with the controller method.

我想为我的ajax调用返回一个新创建的对象的id,而不是返回与控制器方法关联的视图。

2 个解决方案

#1


9  

You can do

你可以做

render :text => @your_object.id

and then cast your responseText to integer in the javascript handler if needed.

然后根据需要将您的responseText转换为javascript处理程序中的整数。

#2


1  

yes , you can .

是的你可以 。

render :text=> "the text that you want to return"

#1


9  

You can do

你可以做

render :text => @your_object.id

and then cast your responseText to integer in the javascript handler if needed.

然后根据需要将您的responseText转换为javascript处理程序中的整数。

#2


1  

yes , you can .

是的你可以 。

render :text=> "the text that you want to return"