ruby-on-railsjsonrenderrespond-to

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 !


Solution

  • Try this in your find method.

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