diff --git a/lib/mail_view.rb b/lib/mail_view.rb index b9e77bf..65d9020 100644 --- a/lib/mail_view.rb +++ b/lib/mail_view.rb @@ -22,7 +22,7 @@ def call(env) end def call(env) - request = Rack::Request.new(env) + @request = Rack::Request.new(env) if request.path_info == "" || request.path_info == "/" links = self.actions.map do |action| @@ -67,6 +67,10 @@ def call(env) def actions public_methods(false).map(&:to_s).sort - ['call'] end + + def request + @request + end def email_template Tilt.new(email_template_path) @@ -110,7 +114,7 @@ def find_preferred_part(mail, formats) end def part_body_url(part) - '?part=%s' % Rack::Utils.escape([part.main_type, part.sub_type].compact.join('/')) + "?#{request.params.merge({'part' => [part.main_type, part.sub_type].compact.join('/')}).to_param}" end def find_part(mail, matching_content_type) diff --git a/lib/mail_view/email.html.erb b/lib/mail_view/email.html.erb index 638a43f..d84c4dd 100644 --- a/lib/mail_view/email.html.erb +++ b/lib/mail_view/email.html.erb @@ -84,8 +84,8 @@ <% if mail.multipart? %>
<% end %> diff --git a/test/test_mail_view.rb b/test/test_mail_view.rb index 33c2b54..8d3d377 100644 --- a/test/test_mail_view.rb +++ b/test/test_mail_view.rb @@ -17,6 +17,15 @@ def plain_text_message yield self if block_given? end end + + def use_request_params_in_preview + locale = request.params['locale'] + Mail.new do + to 'josh@37signals.com' + body "Locale: #{locale}" + yield self if block_given? + end + end def plain_text_message_with_display_names Mail.new do @@ -145,6 +154,11 @@ def test_index assert_match '/html_message', last_response.body assert_match '/multipart_alternative', last_response.body end + + def test_use_request_params_in_preview + get '/use_request_params_in_preview?locale=en&part=' + assert_match 'Locale: en', last_response.body + end def test_mounted_index get '/', {}, 'SCRIPT_NAME' => '/boom'