次のようなコマンドを使用してRailsの足場を生成する場合、rails g scaffold Thing
その煩わしさを回避する方法はありますか
respond_to do |format|
format.html # index.html.erb
format.json { render json: @things }
end
あなたのコントローラーに何か?
Railsでクラスを教えようとしています。まず、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