Created
June 15, 2018 19:47
-
-
Save KustomDeveloper/0cd90d529aafd7bf64d11dcad180c046 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TweetsController < ApplicationController | |
| # GET /tweets | |
| def index | |
| @tweets = Tweet.all | |
| end | |
| # GET /tweets/1 | |
| def show | |
| @tweet = Tweet.find(params[:id]) | |
| end | |
| # GET /tweets/new | |
| def new | |
| @tweet = Tweet.new | |
| end | |
| # GET /tweets/1/edit | |
| def edit | |
| @tweet = Tweet.find(params[:id]) | |
| end | |
| # POST /tweets | |
| def create | |
| @tweet = Tweet.new(tweet_params) | |
| if @tweet.save | |
| redirect_to @tweet, notice: 'Tweet was successfully created.' | |
| else | |
| render :new | |
| end | |
| end | |
| # PATCH/PUT /tweets/1 | |
| def update | |
| @tweet = Tweet.find(params[:id]) | |
| if @tweet.update(tweet_params) | |
| redirect_to @tweet, notice: 'Tweet was successfully updated.' | |
| else | |
| render :edit | |
| end | |
| end | |
| # DELETE /tweets/1 | |
| def destroy | |
| @tweet = Tweet.find(params[:id]) | |
| @tweet.destroy | |
| redirect_to tweets_url, notice: 'Tweet was successfully destroyed.' | |
| end | |
| private | |
| # Never trust parameters from the scary internet, only allow the white list through. | |
| def tweet_params | |
| params.require(:tweet).permit(:content) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment