Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i return a value instead of a view from my controller?

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.

like image 420
Flexo Avatar asked Dec 28 '22 21:12

Flexo


2 Answers

You can do

render :text => @your_object.id

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

like image 54
alex.zherdev Avatar answered Dec 31 '22 10:12

alex.zherdev


yes , you can .

render :text=> "the text that you want to return"
like image 39
NM. Avatar answered Dec 31 '22 12:12

NM.