Когда вы создаете эскиз рельсов с помощью команды типа rails g scaffold Thing
, есть ли способ избежать получения раздражающего
respond_to do |format|
format.html # index.html.erb
format.json { render json: @things }
end
в вашем контроллере?
Я пытаюсь научить класс Rails, и я хотел бы начать с создания ими эшафота, но со всем форматированием json это намного сложнее, чем нужно. Я был бы намного счастливее, если бы они могли создать эшафот, создавший такой контроллер:
class ThingsController < ApplicationController
def index
@things = Thing.all
end
def show
@thing = Thing.find(params[:id])
end
def new
@thing = Thing.new
end
def edit
@thing = Thing.find(params[:id])
end
def create
@thing = Thing.new(params[:thing])
if @thing.save
redirect_to @thing, notice: 'Thing was successfully created.'
else
render: "new"
end
end
end
def update
@thing = Thing.find(params[:id])
if @thing.update_attributes(params[:thing])
redirect_to @thing, notice: 'Thing was successfully updated.'
else
render: "edit"
end
end
end
def destroy
@thing = Thing.find(params[:id])
@thing.destroy
redirect_to things_url
end
end