diff --git a/app/controllers/tsueets_controller.rb b/app/controllers/tsueets_controller.rb new file mode 100644 index 0000000..66b3113 --- /dev/null +++ b/app/controllers/tsueets_controller.rb @@ -0,0 +1,60 @@ +class TsueetsController < ApplicationController + before_action :set_tsueet, only: %i[ show edit update destroy ] + + # GET /tsueets + def index + @tsueets = Tsueet.order(id: :desc) + @tsueet = Tsueet.new + end + + # GET /tsueets/1 + def show + end + + # GET /tsueets/new + def new + @tsueet = Tsueet.new + end + + # GET /tsueets/1/edit + def edit + end + + # POST /tsueets + def create + @tsueet = Tsueet.new(tsueet_params) + + if @tsueet.save + redirect_to tsueets_path, notice: "Tsueet was successfully created." + else + # TODO: バリデーションエラーのときも一覧ページにエラー表示できるように検討する + render :new, status: :unprocessable_entity + end + end + + # PATCH/PUT /tsueets/1 + def update + if @tsueet.update(tsueet_params) + redirect_to @tsueet, notice: "Tsueet was successfully updated.", status: :see_other + else + render :edit, status: :unprocessable_entity + end + end + + # DELETE /tsueets/1 + def destroy + @tsueet.destroy! + redirect_to tsueets_path, notice: "Tsueet was successfully destroyed.", status: :see_other + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_tsueet + @tsueet = Tsueet.find(params.expect(:id)) + end + + # Only allow a list of trusted parameters through. + def tsueet_params + params.expect(tsueet: [ :content ]) + end +end diff --git a/app/models/tsueet.rb b/app/models/tsueet.rb new file mode 100644 index 0000000..e4783b5 --- /dev/null +++ b/app/models/tsueet.rb @@ -0,0 +1,7 @@ +class Tsueet < ApplicationRecord + validates :content, presence: true + + after_create_commit -> { broadcast_refresh_later_to("tsueets") } + after_update_commit -> { broadcast_refresh_later; broadcast_refresh_later_to("tsueets") } + after_destroy_commit -> { broadcast_refresh; broadcast_refresh_later_to("tsueets") } +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9ca9aa9..7154810 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,6 +10,9 @@ <%= yield :head %> + + + <%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %> <%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %> @@ -23,6 +26,9 @@
- <%= yield %> +