Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails : how to render an other action in the controller, in js not in html?

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 !

like image 878
Maxxx Avatar asked Mar 31 '12 20:03

Maxxx


2 Answers

Try this in your find method.

render 'result', :id => @item.id, :format => :js
like image 189
Dia Kharrat Avatar answered Sep 30 '22 10:09

Dia Kharrat


render method only renders views, doesn't call another action

like image 39
mikdiet Avatar answered Sep 30 '22 09:09

mikdiet