Pomiń format JSON w szynach generując rusztowanie
Kiedy generujesz rusztowanie szynowe za pomocą polecenia takiego jakrails g scaffold Thing
czy jest jakiś sposób, aby uniknąć tego irytującego
respond_to do |format|
format.html # index.html.erb
format.json { render json: @things }
end
rzeczy w twoim kontrolerze?
Próbuję uczyć klasy na Railsach i chciałbym zacząć od wygenerowania przez nich rusztowania, ale przy całym formatowaniu jsona jest to znacznie bardziej skomplikowane niż powinno być. Byłbym znacznie bardziej szczęśliwy, gdyby mogli wygenerować rusztowanie, które stworzyło taki kontroler:
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