在我的小型Rails应用中,我想通过json格式更新对象,并成功接收index.json.jbuilder内容(在更新中使用JSON格式的render :index
)。但是由于某种原因,我只是得到一个空数组...我尝试了很多选择而没有成功,因此欢迎您提供任何帮助!提前谢谢
我的路线
resources :coaches, only: [:show] do
resource :calendar, only: :show, defaults: { format: :json }
resources :events, only: [:index, :update], defaults: { format: :json }
end
我的控制器
respond_to :json, only: :index
def index
@events = Event.all
end
def update
respond_to do |format|
if @event.update(event_params)
if params[:commit] == I18n.t('next')
format.html { redirect_to booking_event_confirm_path(@event) }
elsif params[:commit] == I18n.t('confirm')
format.html { redirect_to root_path, notice: "Event was successfully confirmed." }
else
format.html { redirect_to booking_event_path(@event), notice: 'Event was successfully updated.' }
format.json { render :index, status: :ok }
end
else
if params[:commit] == I18n.t('next')
format.html { render :training }
elsif params[:commit] == I18n.t('confirm')
format.html {
# TODO: why is the url not persistent? ('/confirm' being removed even if page display seems ok)
render :confirm
}
else
format.html { render :training }
format.json { render json: @event.errors, status: :unprocessable_entity }
end
end
end
end
答案 0 :(得分:0)
您需要在更新操作中定义terragrunt = {
remote_state {
backend = "s3"
config {
bucket = "xxxxxxx"
key = "${path_relative_to_include()}/terraform.tfstate"
region = "us-east-1"
encrypt = true
dynamodb_table = "yyyyyyyyy"
s3_bucket_tags {
owner = "Ujjwal Singh"
name = "Terraform state storage"
}
dynamodb_table_tags {
owner = "Ujjwal"
name = "Terraform lock for vpc"
}
}
}
}
才能将其呈现为json
@events