I’m working on a PhoneGap mobile app that communicates with a rails3 server using a REST api and json. Authentication is done using devise 2.0.4.
For my own controllers I can specify that rails should wrap the json with the callback to handle the Cross-Domain problem by the following:
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @books, :callback => params[:callback] }
end
notice the:
:callback => params[:callback]
I’m unable to do that with the devise controllers.
How can I get devise to respond to js requests – i.e. json with a callback?
Thanks a lot,
Ariel
It would be better to override devise controllers providing the :callback parameter to renderer or using before_filter somehow. In order to do that copy devise controller(s) from github/local-gem-directory to your app and then edit. But it would be much easier to define a JS views for each action:
If you ain’t done it already start with generating devise views (which is not necessary but would help you to get the idea):
It would generate lots of
*.html.erbfiles inside of yourapp/views/devisefolder. You have to create appropriate*.js.erbnext to them with following contents:PS: Actually you may just put that line into
app/views/application.js.erband skip other steps;)