When there is
def some_action respond_to do |format| format.html {} format.js {} format.json { respond_with @objects} end end
It seems that the html line and js line automatically feed / call the file corresponding to the action name. Both html and js serve one or the other, not both. Is it correct?
Json is called if you have an ajax call in js that received the call and it is requesting data and they need data to respond, right? Do I need to respond to json and js, or just one?
If you do not respond to name and omit all types, does it respond by default to html and js?
When I respond in the controller, and not in the response_to block in each action, does respond_with @objects any argument (: thml ,: js ,: xml ,: json, etc.)?
Alternative syntax:
class TheController < ApplicationController respond_to :html, :js, :json, only: [:some_action, :other_action] def some_action respond_with @objects end end
How does alternative syntax work?
If you use alternative syntax, can you not respond differently to different types of queries? Do you need to do alternative syntax response_to block isntead if you want to react differently? How each of these cases addresses competent degradation in html?
ajax ruby-on-rails
ahnbizcad
source share