Class: Rails::MailersController

Inherits:
ApplicationController show all
Defined in:
railties/lib/rails/mailers_controller.rb

Overview

:nodoc:

Constant Summary

Constants inherited from ActionController::Base

ActionController::Base::MODULES, ActionController::Base::PROTECTED_IVARS

Constants included from ActionController::ParamsWrapper

ActionController::ParamsWrapper::EXCLUDE_PARAMETERS

Constants included from ActiveSupport::Callbacks

ActiveSupport::Callbacks::CALLBACK_FILTER_TYPES

Constants included from ActionController::DataStreaming

ActionController::DataStreaming::DEFAULT_SEND_FILE_DISPOSITION, ActionController::DataStreaming::DEFAULT_SEND_FILE_TYPE

Constants included from ActionController::Rendering

ActionController::Rendering::RENDER_FORMATS_IN_PRIORITY

Constants included from ActionController::RequestForgeryProtection

ActionController::RequestForgeryProtection::CSRF_TOKEN

Constants included from ActionController::Renderers

ActionController::Renderers::RENDERERS

Constants included from ActionController::Redirecting

ActionController::Redirecting::ILLEGAL_HEADER_VALUE_REGEX

Constants included from AbstractController::Rendering

AbstractController::Rendering::DEFAULT_PROTECTED_INSTANCE_VARIABLES

Instance Method Summary collapse

Methods inherited from ActionController::Base

without_modules

Methods included from ActiveSupport::Concern

#append_features, #class_methods, extended, #included, #prepend_features, #prepended

Methods included from ActionController::Instrumentation

#initialize, #redirect_to, #render, #send_data, #send_file

Methods included from ActionController::Rescue

#show_detailed_exceptions?

Methods included from ActiveSupport::Rescuable

#handler_for_rescue, #rescue_with_handler

Methods included from ActiveSupport::Callbacks

#run_callbacks

Methods included from ActionController::HttpAuthentication::Token::ControllerMethods

#authenticate_or_request_with_http_token, #authenticate_with_http_token, #request_http_token_authentication

Methods included from ActionController::HttpAuthentication::Digest::ControllerMethods

#authenticate_or_request_with_http_digest, #authenticate_with_http_digest, #request_http_digest_authentication

Methods included from ActionController::HttpAuthentication::Basic::ControllerMethods

#authenticate_or_request_with_http_basic, #authenticate_with_http_basic, #http_basic_authenticate_or_request_with, #request_http_basic_authentication

Methods included from ActionController::Rendering

#render, #render_to_body, #render_to_string

Methods included from AbstractController::Helpers

#_helpers

Methods included from AbstractController::Helpers::Resolution

#all_helpers_from_path, #helper_modules_from_paths, #modules_for_helpers

Methods included from ActionController::RequestForgeryProtection

#commit_csrf_token, #initialize, #reset_csrf_token

Methods included from ActionController::FormBuilder

#default_form_builder

Methods included from ActionController::StrongParameters

#params, #params=

Methods included from ActionController::ImplicitRender

#default_render, #method_for_action

Methods included from ActionController::BasicImplicitRender

#default_render, #send_action

Methods included from ActionController::MimeResponds

#respond_to

Methods included from ActionController::ConditionalGet

#expires_in, #expires_now, #fresh_when, #http_cache_forever, #no_store, #stale?

Methods included from ActionController::Head

#head

Methods included from ActionController::Renderers

#_render_to_body_with_renderer, _render_with_renderer_method_name, add, remove, #render_to_body

Methods included from ActionView::Layouts

#_process_render_template_options, #action_has_layout?, #initialize

Methods included from ActionView::Rendering

#initialize, #process, #render_to_body, #view_context, #view_context_class, #view_renderer

Methods included from ActionView::ViewPaths

#_prefixes, #append_view_path, #details_for_lookup, #lookup_context, #prepend_view_path

Methods included from ActionController::Redirecting

_compute_redirect_to_location, #_compute_redirect_to_location, #redirect_back, #redirect_back_or_to, #redirect_to, #url_from

Methods included from ActionController::UrlFor

#initialize, #url_options

Methods included from AbstractController::UrlFor

#_routes

Methods included from ActionDispatch::Routing::UrlFor

#full_url_for, #initialize, #route_for, #url_for, #url_options

Methods included from ActionDispatch::Routing::PolymorphicRoutes

#polymorphic_path, #polymorphic_url

Methods included from ActionController::Helpers

#helpers

Methods included from AbstractController::Translation

#localize, #translate

Methods included from AbstractController::Rendering

#render, #render_to_body, #render_to_string, #rendered_format, #view_assigns

Methods inherited from ActionController::Metal

action, action_encoding_template, #content_type, #content_type=, #controller_name, controller_name, dispatch, #dispatch, #headers, #initialize, #location, #location=, make_response!, #media_type, middleware, #params, #params=, #performed?, #request, #reset_session, #response, #response=, #response_body=, #session, #set_request!, #set_response!, #status, #status=, #to_a, #url_for, use

Methods included from ActionController::Testing::Functional

#clear_instance_variables_between_requests, #recycle!

Methods inherited from AbstractController::Base

abstract!, action_methods, #action_methods, #action_name, #available_action?, clear_action_methods!, controller_path, #controller_path, eager_load!, #formats, inherited, #inspect, internal_methods, method_added, #performed?, #process, #response_body, supports_path?

Methods included from ActiveSupport::DescendantsTracker

clear, #descendants, descendants, disable_clear!, reject!, subclasses

Methods included from ActiveSupport::Configurable

#config

Instance Method Details

#downloadObject



22
23
24
25
26
27
28
29
30
# File 'railties/lib/rails/mailers_controller.rb', line 22

def download
  @email_action = File.basename(params[:path])
  if @preview.email_exists?(@email_action)
    @email = @preview.call(@email_action, params)
    send_data @email.to_s, filename: "#{@email_action}.eml"
  else
    raise AbstractController::ActionNotFound, "Email '#{@email_action}' not found in #{@preview.name}"
  end
end

#indexObject



17
18
19
20
# File 'railties/lib/rails/mailers_controller.rb', line 17

def index
  @previews = ActionMailer::Preview.all
  @page_title = "Action Mailer Previews"
end

#previewObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'railties/lib/rails/mailers_controller.rb', line 32

def preview
  if params[:path] == @preview.preview_name
    @page_title = "Action Mailer Previews for #{@preview.preview_name}"
    render action: "mailer"
  else
    @email_action = File.basename(params[:path])

    if @preview.email_exists?(@email_action)
      @page_title = "Mailer Preview for #{@preview.preview_name}##{@email_action}"
      @email = @preview.call(@email_action, params)
      @attachments = attachments_for(@email).reject { |filename, attachment| attachment.inline? }
      @inline_attachments = attachments_for(@email).select { |filename, attachment| attachment.inline? }

      if params[:part]
        part_type = Mime::Type.lookup(params[:part])

        if part = find_part(part_type)
          response.content_type = part_type
          render plain: part.respond_to?(:decoded) ? part.decoded : part
        else
          raise AbstractController::ActionNotFound, "Email part '#{part_type}' not found in #{@preview.name}##{@email_action}"
        end
      else
        @part = find_preferred_part(request.format, Mime[:html], Mime[:text])
        render action: "email", layout: false, formats: [:html]
      end
    else
      raise AbstractController::ActionNotFound, "Email '#{@email_action}' not found in #{@preview.name}"
    end
  end
end