Sunday, 29 September 2013

Rails controller action behavior without respond_to

Rails controller action behavior without respond_to

Rails Scaffold generator create some actions in a controller with
respond_to and some without it.
For example:
GET /replaces/new
GET /replaces/new.json
def new
@replace = Replace.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @replace }
end
end
GET /replaces/1/edit
def edit
@replace = Replace.find(params[:id])
end
I understand that Rails renders the view that has the same name as the
action. If I have multiple views with the same name (in different
formats), I have to specify which one you want in the request and use the
respond_to method to respond accordingly.
Questions:
Why the Scaffold generator create some actions without respond_to ?
What will be the behavior if there no respond_to and requests are coming
with different format? HTML? AJAX?

No comments:

Post a Comment