Sha256: b51e39002168de28fe1e301aa81aaae76487bbce27878996b1feef84c34ba9f0

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

module PoBox
  class EmailsController < ApplicationController
    before_action :set_inbox
    before_action :set_email, only: %i[show edit update destroy]

    # GET /emails
    def index
      @emails = Email.all
    end

    # GET /emails/1
    def show
    end

    # GET /emails/new
    def new
      @email = Email.new
    end

    # GET /emails/1/edit
    def edit
    end

    # POST /emails
    def create
      @email = Email.new(email_params)

      if @email.save
        redirect_to inbox_email_path(@inbox, @email), notice: "Email was successfully created."
      else
        render :new, status: :unprocessable_entity
      end
    end

    # PATCH/PUT /emails/1
    def update
      if @email.update(email_params)
        redirect_to inbox_email_path(@inbox, @email), notice: "Email was successfully updated."
      else
        render :edit, status: :unprocessable_entity
      end
    end

    # DELETE /emails/1
    def destroy
      @email.destroy
      redirect_to inbox_emails_url(@inbox), notice: "Email was successfully destroyed."
    end

    private

    def set_inbox
      @inbox = Inbox.find(params[:inbox_id])
    rescue ActiveRecord::RecordNotFound
      redirect_to po_box_inboxes_path, notice: "Inbox not found"
    end

    # Use callbacks to share common setup or constraints between actions.
    def set_email
      @email = Email.find(params[:id])
    end

    # Only allow a list of trusted parameters through.
    def email_params
      params.require(:email).permit(:inbox_id, :cc, :from, :multipart, :read, :subject, :to, :message_id)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
po_box-0.1.2 app/controllers/po_box/emails_controller.rb
po_box-0.1.0 app/controllers/po_box/emails_controller.rb