I am trying Rails to render a template .html.erbusing an ajax request under certain conditions. By default, I return the file .js.erbwhen I send an ajax request.
.html.erb
.js.erb
I will not go into why I am doing this, but I was wondering if there is a way to indicate when I send the request via ajax that I would like to use html content and not js, OR alternatively if there is a way to refactor the following in Rails 3.1:
respond_to do |format| format.html format.js do if params[:page].nil? render "home.html.erb" else render "home.js.erb" end end end
Thank!
Assuming you are using jquery, you can set the dataType option, i.e.
$.ajax('some/page', {dataType: 'html'})
Or
$.get('some/page', function(){ //callback}, 'html')
URL (.. request '/some/page.html) ( , )