Setting rails to create scaffolds

I had a problem before the command "rails generate test scaffold: string names" created by such controllers:

class Teste < ApplicationController before_action :set_teste, only: [:show, :edit, :update, :destroy # GET /testes # GET /testes.json def index @testes = Teste.all end # GET /testes/1 # GET /testes/1.json def show end # GET /testes/new def new @teste = Teste.new end # GET /testes/1/edit def edit end # POST /testes # POST /testes.json def create @teste = Teste.new(teste_params) respond_to do |format| if @teste.save format.html { redirect_to testes_path, notice: 'Teste cadastrado.' } format.json { render :show, status: :created, location: @teste } else format.html { render :new } format.json { render json: @teste.errors, status: :unprocessable_entity } end end end # PATCH/PUT /testes/1 # PATCH/PUT /testes/1.json def update respond_to do |format| if @teste.update(teste_params) format.html { redirect_to testes_path, notice: 'Teste atualizado.' } format.json { render :show, status: :ok, location: @teste } else format.html { render :edit } format.json { render json: @teste.errors, status: :unprocessable_entity } end end end # DELETE /testes/1 # DELETE /testes/1.json def destroy @teste.destroy respond_to do |format| format.html { redirect_to testes_url, notice: 'Teste excluΓ­do.' } format.json { head :no_content } end end 

I don’t know why, but now another format is being created

 class TestesController < ApplicationController before_action :set_teste, only: [:show, :edit, :update, :destroy] def index @testes = Teste.all respond_with(@testes) end def show respond_with(@teste) end def new @teste = Teste.new respond_with(@teste) end def edit end def create @teste = Teste.new(teste_params) @teste.save respond_with(@teste) end def update @teste.update(teste_params) respond_with(@teste) end 

What could it be? Why has this changed?

I would go back to the previous format, because my whole system is in the first format

+5
source share
1 answer

The reason for this behavior is probably some stone.

I had the same problem because the latest version of Devise, which now comes with stone defendants.

If this is your case, then a quick fix adds the following line to the aplication.rb file:

config.app_generators.scaffold_controller :scaffold_controller

More details here:

https://github.com/rails/rails/issues/17290

https://github.com/plataformatec/responders/issues/94

+2
source

Source: https://habr.com/ru/post/1205528/


All Articles