Friday, November 27, 2026
HomeRuby On RailsNative Dialog | Drifting Ruby

Native Dialog | Drifting Ruby


# app/controllers/notes_controller.rb
class NotesController < ApplicationController
  # GET /notes
  def index
    @notes = Notice.all
    @be aware = Notice.new
  finish

  # POST /notes
  def create
    @be aware = Notice.new(note_params)

    if @be aware.save
      redirect_to notes_path, discover: "Notice was efficiently created."
    else
      render :new, standing: :unprocessable_content
    finish
  finish

  # DELETE /notes/1
  def destroy
    @be aware = Notice.discover(params.count on(:id))
    @be aware.destroy!
    redirect_to notes_path, discover: "Notice was efficiently destroyed.", standing: :see_other
  finish

  non-public

    # Solely permit a listing of trusted parameters via.
    def note_params
      params.count on(be aware: [ :title, :body ])
    finish
finish
# app/views/notes/index.html.erb
<% content_for :title, "Notes" %>

<button command="show-modal" commandfor="new_note" class="bg-slate-800 text-white px-4 py-2 cursor-pointer">
  New Notice
</button>

<dialog id="new_note"
  class="p-6 border-2 border-slate-400 shadow-lg backdrop:bg-slate-900/50">
  <h2 class="font-bold text-xl mb-4">New Notice</h2>
  <%= form_with mannequin: @be aware do |type| %>
    <%= type.text_field :title, class: "w-full border-2 border-slate-300 p-2 mb-3" %>
    <%= type.text_area :physique, rows: 4, class: "w-full border-2 border-slate-300 p-2 mb-3" %>

    <button sort="button" command="shut" commandfor="new_note" class="px-4 py-2 cursor-pointer">
      Cancel
    </button>

    <%= type.submit "Save", class: "bg-slate-800 text-white px-4 py-2 cursor-pointer" %>
  <% finish %>
</dialog>

<div class="w-full">
  <div class="flex justify-between items-center">
    <h1 class="font-bold text-4xl">Notes</h1>
  </div>

  <div id="notes" class="min-w-full divide-y divide-gray-200 space-y-5">
    <% if @notes.any? %>
      <% @notes.every do |be aware| %>
        <div class="flex flex-col sm:flex-row justify-between items-center pb-5 sm:pb-0">
          <%= be aware.title %>
          <div class="w-full sm:w-auto flex flex-col sm:flex-row space-x-2 space-y-2">
            <button command="toggle-popover" commandfor="menu_<%= be aware.id %>">
              &hellip;
            </button>
            <div popover id="menu_<%= be aware.id %>" class="note-menu">
              <%= button_to "Destroy", be aware, methodology: :delete, information: { turbo_confirm: "Are you certain?" } %>
            </div>
          </div>
        </div>
      <% finish %>
    <% else %>
      <p class="text-center my-10">No notes discovered.</p>
    <% finish %>
  </div>
</div>
# app/belongings/stylesheets/utility.css
dialog:modal {
  margin: auto;
}

.note-menu {
  place: fastened;
  inset: auto;
  margin: 0;
  position-area: backside span-left;
  border: 2px stable grey;
  background: white;
}
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments