उत्पन्न जब आप rails g scaffold Thing
की तरह एक आदेश का उपयोग कर एक रेल पाड़ उत्पन्न वहाँ किसी भी तरह से अपने नियंत्रक में हो रही है कि कष्टप्रदरेल में छोड़ें JSON प्रारूप पाड़
respond_to do |format|
format.html # index.html.erb
format.json { render json: @things }
end
सामान से बचने के लिए है?
मैं रेल पर एक कक्षा पढ़ाने की कोशिश कर रहा हूं और मैं उन्हें एक मचान उत्पन्न करके शुरू करना चाहता हूं, लेकिन सभी जेसन स्वरूपण के साथ यह बहुत जटिल है।
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
बकवास, तुमने मुझे मार दिया! बहुत बढ़िया जवाब! –