When doing rails generate scaffold Banana
, bananas_controller.rb
has the following code:
# POST /bananas or /bananas.json def create @banana = Banana.new(banana_params) respond_to do |format| if @banana.save format.html { redirect_to banana_url(@banana), notice: "Banana was successfully created." } format.json { render :show, status: :created, location: @banana } else format.html { render :new, status: :unprocessable_entity } format.json { render json: @banana.errors, status: :unprocessable_entity } end end end
But when I look at the railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt
template in the Rails codebase, the create
method is only defined like so:
# POST <%= route_url %> def create @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %> if @<%= orm_instance.save %> redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully created.") %> else render :new, status: :unprocessable_entity end end
There is no mention of respond_to do |format|
whatsoever. Where in the Rails codebase is respond_to do |format|
added? I grepped the whole project to no avail.