public
Created

  • Download Gist
widgets_controller.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
class WidgetsController < ApplicationController
# GET /widgets
# GET /widgets.json
def index
@widgets = Widget.all
 
respond_to do |format|
format.html # index.html.erb
format.json { render json: @widgets }
end
end
 
# GET /widgets/1
# GET /widgets/1.json
def show
@widget = Widget.find(params[:id])
 
respond_to do |format|
format.html # show.html.erb
format.json { render json: @widget }
end
end
 
# GET /widgets/new
# GET /widgets/new.json
def new
@widget = Widget.new
 
respond_to do |format|
format.html # new.html.erb
format.json { render json: @widget }
end
end
 
# GET /widgets/1/edit
def edit
@widget = Widget.find(params[:id])
end
 
# POST /widgets
# POST /widgets.json
def create
@widget = Widget.new(params[:widget])
 
respond_to do |format|
if @widget.save
format.html { redirect_to @widget, notice: 'Widget was successfully created.' }
format.json { render json: @widget, status: :created, location: @widget }
else
format.html { render action: "new" }
format.json { render json: @widget.errors, status: :unprocessable_entity }
end
end
end
 
# PUT /widgets/1
# PUT /widgets/1.json
def update
@widget = Widget.find(params[:id])
 
respond_to do |format|
if @widget.update_attributes(params[:widget])
format.html { redirect_to @widget, notice: 'Widget was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @widget.errors, status: :unprocessable_entity }
end
end
end
 
# DELETE /widgets/1
# DELETE /widgets/1.json
def destroy
@widget = Widget.find(params[:id])
@widget.destroy
 
respond_to do |format|
format.html { redirect_to widgets_url }
format.json { head :no_content }
end
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.