Sha256: a9f561dc0efdbba23f969251242528a082735dd36052648b3eb23e04e631b193

Contents?: true

Size: 1.59 KB

Versions: 76

Compression:

Stored size: 1.59 KB

Contents

class ContactsController < ApplicationController
  include ActionView::RecordIdentifier

  before_action :set_contact, only: %i[show edit update destroy]
  before_action :all_contacts

  # GET /contacts or /contacts.json
  def index
    @contacts = Contact.search(params)
  end

  # GET /contacts/1 or /contacts/1.json
  def show
  end

  # GET /contacts/new
  def new
    @contact = Contact.new
  end

  # GET /contacts/1/edit
  def edit
  end

  # POST /contacts or /contacts.json
  def create
    @contact = Contact.new(contact_params)

    if @contact.save
      flash[:notice] = 'Contact was successfully created.'
    else
      render :new, status: :unprocessable_entity
    end
  end

  # PATCH/PUT /contacts/1 or /contacts/1.json
  def update
    if @contact.update(contact_params)
      flash[:notice] = "Contact updated"
    else
      render :edit, status: :unprocessable_entity
    end
  end

  def destroy
    @contact.destroy
    flash[:notice] = "Contact removed"
    render turbo_stream: [
      turbo_stream.update("flash", partial: "shared/flash"),
      turbo_stream.remove(dom_id(@contact)),
      turbo_stream.update("contacts-count", partial: "contacts/count", locals: { contacts: @contacts })
    ]
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_contact
      @contact = Contact.find(params.require(:id))
    end

    def contact_params
      params.require(:contact).permit(:name, :age, :email)
    end
    # def contact_params
    #   params.require(:contact).permit!
    # end

    def all_contacts
      @contacts = Contact.all
    end

end

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
rails_app_generator-0.3.6 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.3.5 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.3.4 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.3.3 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.3.2 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.3.1 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.3.0 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.2.43 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.2.42 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.2.41 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.2.40 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.2.39 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.2.38 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.2.37 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.2.36 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.2.35 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.2.34 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.2.33 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.2.32 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb
rails_app_generator-0.2.31 after_templates/rag/tailwind_hotwire_form_search/contacts_controller.rb