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