当您使用命令生成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 …
Run Code Online (Sandbox Code Playgroud) 我如何写两个日期范围的查询?唯一的条件是必须通过一个查询检索此数据.谢谢.
UPD:或如何在一个集合中结合2个查询?不是数组