Created
February 26, 2021 05:29
-
-
Save catmando/a87ae4286399f7f699fbf7fc9d4e8c4f to your computer and use it in GitHub Desktop.
Hyperstack vs Hotwire controllers:
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 LikesController < ApplicationController | |
before_action :set_tweet | |
def create | |
@tweet.increment! :likes_count | |
redirect_to @tweet | |
end | |
private | |
def set_tweet | |
@tweet = Tweet.find(params[:tweet_id]) | |
end | |
end | |
class RetweetsController < ApplicationController | |
before_action :set_tweet | |
def create | |
@tweet.increment! :retweets_count | |
redirect_to @tweet | |
end | |
private | |
def set_tweet | |
@tweet = Tweet.find(params[:tweet_id]) | |
end | |
end | |
class TweetsController < ApplicationController | |
before_action :set_tweet, only: [:show, :edit, :update, :destroy] | |
# GET /tweets | |
# GET /tweets.json | |
def index | |
@tweets = Tweet.all | |
@tweet = Tweet.new | |
end | |
# GET /tweets/1 | |
# GET /tweets/1.json | |
def show | |
end | |
# GET /tweets/new | |
def new | |
@tweet = Tweet.new | |
end | |
# GET /tweets/1/edit | |
def edit | |
end | |
# POST /tweets | |
# POST /tweets.json | |
def create | |
@tweet = Tweet.new(tweet_params) | |
respond_to do |format| | |
if @tweet.save | |
format.html { redirect_to tweets_url, notice: 'Tweet was successfully created.' } | |
format.json { render :show, status: :created, location: @tweet } | |
else | |
format.turbo_stream { render turbo_stream: turbo_stream.replace(@tweet, partial: "tweets/form", locals: { tweet: @tweet}) } | |
format.html { render :new } | |
format.json { render json: @tweet.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# PATCH/PUT /tweets/1 | |
# PATCH/PUT /tweets/1.json | |
def update | |
respond_to do |format| | |
if @tweet.update(tweet_params) | |
format.html { redirect_to @tweet, notice: 'Tweet was successfully updated.' } | |
format.json { render :show, status: :ok, location: @tweet } | |
else | |
format.html { render :edit } | |
format.json { render json: @tweet.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment