1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- class MicropostsController < ApplicationController
- # GET /microposts
- # GET /microposts.json
- def index
- @microposts = Micropost.all
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @microposts }
- end
- end
- # GET /microposts/1
- # GET /microposts/1.json
- def show
- @micropost = Micropost.find(params[:id])
- respond_to do |format|
- format.html # show.html.erb
- format.json { render json: @micropost }
- end
- end
- # GET /microposts/new
- # GET /microposts/new.json
- def new
- @micropost = Micropost.new
- respond_to do |format|
- format.html # new.html.erb
- format.json { render json: @micropost }
- end
- end
- # GET /microposts/1/edit
- def edit
- @micropost = Micropost.find(params[:id])
- end
- # POST /microposts
- # POST /microposts.json
- def create
- @micropost = Micropost.new(params[:micropost])
- respond_to do |format|
- if @micropost.save
- format.html { redirect_to @micropost, notice: 'Micropost was successfully created.' }
- format.json { render json: @micropost, status: :created, location: @micropost }
- else
- format.html { render action: "new" }
- format.json { render json: @micropost.errors, status: :unprocessable_entity }
- end
- end
- end
- # PUT /microposts/1
- # PUT /microposts/1.json
- def update
- @micropost = Micropost.find(params[:id])
- respond_to do |format|
- if @micropost.update_attributes(params[:micropost])
- format.html { redirect_to @micropost, notice: 'Micropost was successfully updated.' }
- format.json { head :ok }
- else
- format.html { render action: "edit" }
- format.json { render json: @micropost.errors, status: :unprocessable_entity }
- end
- end
- end
- # DELETE /microposts/1
- # DELETE /microposts/1.json
- def destroy
- @micropost = Micropost.find(params[:id])
- @micropost.destroy
- respond_to do |format|
- format.html { redirect_to microposts_url }
- format.json { head :ok }
- end
- end
- end
|