当你使用如下命令rails g scaffold Thing
产生导轨支架是有什么办法避免让那个讨厌的跳过JSON格式生成脚手架
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
废话,你打我吧!很好的回答! –