Class: RailsMail::EmailsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- RailsMail::EmailsController
- Defined in:
- app/controllers/rails_mail/emails_controller.rb
Instance Method Summary collapse
- #destroy ⇒ Object
- #destroy_all ⇒ Object
-
#index ⇒ Object
GET /emails.
-
#show ⇒ Object
GET /emails/1.
Methods included from TurboHelper
#rails_mail_turbo_frame_tag, #rails_mail_turbo_stream, #rails_mail_turbo_stream_from
Instance Method Details
#destroy ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/rails_mail/emails_controller.rb', line 32 def destroy @email = Email.find(params[:id]) @current_email_id = session[:current_email_id] @email.destroy respond_to do |format| format.html { redirect_to emails_path } format.turbo_stream end end |
#destroy_all ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/controllers/rails_mail/emails_controller.rb', line 43 def destroy_all Email.destroy_all respond_to do |format| format.html { redirect_to emails_path } format.turbo_stream end end |
#index ⇒ Object
GET /emails
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/rails_mail/emails_controller.rb', line 4 def index @emails = Email.order(created_at: :desc) @emails = @emails.search(params[:q]) if params[:q].present? paginated = paginate_with_next_page(@emails, page: params[:page].to_i) @emails, @next_page = paginated.items, paginated.next_page @email = params[:id] ? Email.find(params[:id]) : @emails.last # we're not paginating, so it means we're either the initial index page # load or we're searching. In which case run an "update" turbo stream # to replace all the results. @turbo_stream_action = paginating? ? "append" : "update" respond_to do |format| format.html format.turbo_stream if params[:q].present? || params[:page].present? end end |
#show ⇒ Object
GET /emails/1
22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/rails_mail/emails_controller.rb', line 22 def show @emails = Email.order(created_at: :desc) paginated = paginate_with_next_page(@emails, page: params[:page].to_i) @emails, @next_page = paginated.items, paginated.next_page @email = Email.find(params[:id]) session[:current_email_id] = @email.id render :show end |