class EmailsController < ApplicationController before_action :set_email, only: [:show, :mark_as_read, :body_preview] def index @emails = Email.where(mailbox_id: params[:mailbox_id]) @emails = @emails.search(params[:q]) if params[:q].present? render(layout: false) end def show @selected = params[:selected] @email.mark_as_read! unless @email.read? end def body_preview render(layout: false) end def set_email @email = Email.find(params[:id]) @mailbox = @email.mailbox end end