【发布时间】:2012-12-11 05:56:32
【问题描述】:
当你使用rails g scaffold Thing 之类的命令生成rails 脚手架时,有什么办法可以避免烦人
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
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 scaffolding