Skip to content

Commit

Permalink
Ensure render :file works inside templates
Browse files Browse the repository at this point in the history
  • Loading branch information
lifo committed Jun 5, 2008
1 parent a04bfac commit 27b68e3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion actionmailer/lib/action_mailer/base.rb
Expand Up @@ -530,14 +530,15 @@ def initialize_defaults(method_name)
end

def render_message(method_name, body)
render :file => method_name, :body => body
render :file => method_name, :body => body, :use_full_path => true
end

def render(opts)
body = opts.delete(:body)
if opts[:file] && opts[:file] !~ /\//
opts[:file] = "#{mailer_name}/#{opts[:file]}"
end
opts[:use_full_path] = true
initialize_template_class(body).render(opts)
end

Expand Down
3 changes: 2 additions & 1 deletion actionpack/lib/action_view/base.rb
Expand Up @@ -253,6 +253,7 @@ def render(options = {}, local_assigns = {}, &block) #:nodoc:
elsif options == :update
update_page(&block)
elsif options.is_a?(Hash)
use_full_path = options[:use_full_path]
options = options.reverse_merge(:locals => {}, :use_full_path => true)

if partial_layout = options.delete(:layout)
Expand All @@ -266,7 +267,7 @@ def render(options = {}, local_assigns = {}, &block) #:nodoc:
end
end
elsif options[:file]
render_file(options[:file], options[:use_full_path], options[:locals])
render_file(options[:file], use_full_path || false, options[:locals])
elsif options[:partial] && options[:collection]
render_partial_collection(options[:partial], options[:collection], options[:spacer_template], options[:locals])
elsif options[:partial]
Expand Down
10 changes: 10 additions & 0 deletions actionpack/test/controller/new_render_test.rb
Expand Up @@ -68,6 +68,11 @@ def render_file_with_instance_variables
path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb')
render :file => path
end

def render_file_from_template
@secret = 'in the sauce'
@path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb'))
end

def render_file_with_locals
path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals.erb')
Expand Down Expand Up @@ -531,6 +536,11 @@ def test_render_file_with_locals
get :render_file_with_locals
assert_equal "The secret is in the sauce\n", @response.body
end

def test_render_file_from_template
get :render_file_from_template
assert_equal "The secret is in the sauce\n", @response.body
end

def test_attempt_to_access_object_method
assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }
Expand Down
@@ -0,0 +1 @@
<%= render :file => @path %>

0 comments on commit 27b68e3

Please sign in to comment.