Generate inbox entries using Turbo Streams

This commit is contained in:
Andreas Nedbal 2022-11-17 21:55:01 +01:00 committed by Andreas Nedbal
parent 960b20f407
commit d3eae22f13
3 changed files with 19 additions and 1 deletions

View File

@ -52,4 +52,21 @@ class InboxController < ApplicationController
format.turbo_stream { render "show", layout: false, status: :see_other }
end
end
def create
question = Question.create!(content: QuestionGenerator.generate,
author_is_anonymous: true,
author_identifier: "justask",
user: current_user)
inbox = Inbox.create!(user: current_user, question_id: question.id, new: true)
respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.prepend("entries", partial: "inbox/entry", locals: { i: inbox })
end
format.html { redirect_to inbox_path }
end
end
end

View File

@ -5,7 +5,7 @@
= f.text_field :author, value: params[:author], placeholder: t(".author.placeholder"), prepend: "@", hide_label: true,
append: f.button(t(".author.button"), name: nil, class: "btn btn-light", id: "ib-author")
.d-flex.ml-auto.mt-2.mt-md-0
%button.btn.btn-info.mr-auto{ type: :button, id: "ib-generate-question" }
= button_to inbox_create_path, class: "btn btn-info mr-auto" do
= t(".questions.button")
.button-group.ml-1
%button.btn.btn-default{ title: t(".share.heading"), data: { toggle: :dropdown }, aria: { expanded: false } }

View File

@ -143,6 +143,7 @@ Rails.application.routes.draw do
match "/notifications(/:type)", to: "notifications#index", via: [:get, :post], as: :notifications, defaults: { type: "new" }
post "/inbox/create", to: "inbox#create", as: :inbox_create
match "/inbox(/:author)", via: [:get, :post], to: "inbox#show", as: :inbox
match "/user/:username(/p/:page)", to: "user#show", via: [:get, :post], defaults: { page: 1 }