0

Rails 2.3.18

I have a Answer controller with an index function like this :

def index
  respond_to do |format|
    format.js { }
    format.all { redirect_to ... }
  end
end

I have a anwers/index.js.erb associated to this index action, for :js format.

I just enter URL /answers/ in my browser to call the index function, and the result is surprising : this is the index.js displayed as a text.

Something is wrong with this, but I don't understand what !

I log the mime type on the index action, and this is "text/html", corresponding to :html format. Why :js format is called instead of :all format ?

Regards

pierallard
  • 3,326
  • 3
  • 21
  • 48
  • You can't be using Ruby 2.3.18. Do you mean Rails 2.3.18? Also, what URL are you entering into the browser? You just said "I enter URL". The more details you can provide the better – Kyle Decot Jul 12 '13 at 13:50
  • 1
    Try using `format.html` instead of format.all – Barbared Jul 12 '13 at 13:57

2 Answers2

0

Try using format.html and format.js without passing a block as shown below. I've never seen format.all used before.

def index
  respond_to do |format|
    format.js
    format.html
  end
end
Kyle Decot
  • 20,715
  • 39
  • 142
  • 263
  • The documentation in Apidock use this :all format : http://apidock.com/rails/Mime http://apidock.com/rails/ActionController/MimeResponds/InstanceMethods/respond_to#604-A-catch-all-format – pierallard Jul 12 '13 at 14:00
0

Try this

def index
  respond_to do |format|
    format.html{redirect_to ...}
    format.js {}
  end
end
Debadatt
  • 5,935
  • 4
  • 27
  • 40