mat*_*fel 16 ruby-on-rails scaffolding ruby-on-rails-3
当您使用命令生成rails脚手架时,rails g scaffold Thing
有任何方法可以避免令人讨厌
respond_to do |format|
format.html # index.html.erb
format.json { render json: @things }
end
Run Code Online (Sandbox Code Playgroud)
你控制器里的东西?
我正在尝试在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
Run Code Online (Sandbox Code Playgroud)
Vad*_*eev 13
只需克隆文件
到你的
lib/rails/generators/rails/scaffold_controller/templates/controller.rb
Run Code Online (Sandbox Code Playgroud)
应用程序中的路径并自定义您想要的内容.此外,您可以编写自己的脚手架生成器(http://guides.rubyonrails.org/generators.html).