This project is archived and is in readonly mode.
view_paths does not work with actions or partials
Reported by Chris Vincent | July 1st, 2008 @ 01:10 AM | in 2.x
I've been unable to get my view_paths working as I would expect when I use the :action and :partial options for render. It only seems to affect the :template option.
Comments and changes to this ticket
-
Pratik July 1st, 2008 @ 12:42 PM
- State changed from new to incomplete
Could you please provide a failing test case ?
Thanks.
-
Chris Vincent July 1st, 2008 @ 09:24 PM
Okay. I managed to test for render :action but I'm not sure how to test that a specific partial got rendered. Here's the code:
### app/controllers/view_paths_test_controller.rb class ViewPathsTestController < ApplicationController before_filter do prepend_view_path 'views/overrides' end def action_without_override render :action => 'action_without_override' end def action_with_override render :action => 'action_with_override' end def partial_without_override render :action => 'partial_without_override' end def partial_with_override render :action => 'partial_with_override' end end ### test/functional/view_paths_test_controller_test.rb require File.dirname(__FILE__) + '/../test_helper' class ViewPathsTestControllerTest < ActionController::TestCase def setup @controller = ViewPathsTestController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new end def test_action_without_override get :action_without_override assert_template 'view_paths_test/action_without_override' end def test_action_with_override get :action_with_override assert_template 'overrides/action_with_override' end end
I have the following templates:
- views/view_paths_test/action_without_override.html.erb
- views/view_paths_test/action_with_override.html.erb
- views/view_paths_test/partial_without_override.html.erb
- views/view_paths_test/_partial_without_override.html.erb
- views/view_paths_test/partial_with_override.html.erb
- views/view_paths_test/_partial_with_override.html.erb
- views/overrides/action_with_override.html.erb
- views/overrides/_partial_with_override.html.erb
The first test passes, the second fails since view_paths_test/action_with_override.html.erb is rendered instead of overrides/action_with_override.html.erb. Again, I'm not sure how to assert that a partial got rendered so I don't know how to write tests for that, although all the actual code and templates are in place for demonstration.
-
Chris Vincent July 1st, 2008 @ 09:25 PM
- Tag changed from actionpack, bug to actionpack, bug, tested
By the way, these were performed with 2.0.2.
-
Ben Marini July 11th, 2008 @ 07:24 PM
I tested out your code in Rails 2.1 and had the same result.
A couple problems with your test though:
prepend_view_path adds a new base path, so you would need:
views/overrides/view_paths_test/action_with_override.html.erb
instead of
views/overrides/action_with_override.html.erb
I was able to get #prepend_view_paths to work as expected by making the following changes to your code example:
My templates:
- views/view_paths_test/action_without_override.html.erb
- views/view_paths_test/action_with_override.html.erb
- views/view_paths_test/partial_without_override.html.erb
- views/view_paths_test/_partial_without_override.html.erb
- views/view_paths_test/partial_with_override.html.erb
- views/view_paths_test/_partial_with_override.html.erb
- other_views/view_paths_test/action_with_override.html.erb
- other_views/view_paths_test/_partial_with_override.html.erb
-
Ben Marini July 11th, 2008 @ 07:27 PM
Whoops, didn't like my formatting:
class ViewPathsTestController < ApplicationController # Doesn't work when using block form! before_filter :override_views def override_views self.prepend_view_path RAILS_ROOT + '/app/other_views' end
-
Chris Vincent July 11th, 2008 @ 07:46 PM
Aha, that clears it up! The docs don't explain this very well. The examples provided are:
ArticleController.prepend_view_path("views/default") ArticleController.prepend_view_path(["views/default", "views/custom"])
Also, is there a method for asserting that a partial was rendered? It would be reassuring to have tests for the partials as well.
-
josh December 15th, 2008 @ 09:48 PM
- State changed from incomplete to wontfix
-
Tiago Bastos January 22nd, 2009 @ 06:19 AM
- Assigned user set to josh
Marini don't use prepend_view_path with a before_filter in Rails 2.2, that will use a lot of your file system (stat, stat64) couse will re-index the paths all time (every request).
Try to save a Path object in some place and use-it instead of Strings. Other way is like the code says, preload at start-up.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>