SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Accessing ancester method is fine but asking for child template

    Hello,

    I have a strange situation where I'm making a dummy class that inherits from a parent class. it calls the parent method fine but is asking for the child class to provide a view template.

    I'm creating the dummy class for testing purposes in a functional test.

    Heres basically what I'm trying:

    and the error:

    Code:
    class ParentController < ApplicationController
       
        def parent_method
            #... code
        end
    end
    
    class DummyController < ParentController
         #no child method
    end
    
    class ParentControllerTest < Test::Unit::TestCase
      fixtures :users
        
      def setup
        @controller = DummyController.new
        @request    = ActionController::TestRequest.new
        @response   = ActionController::TestResponse.new
    
      def test_parent_method
        post :parent_method
        assert_response :success
      end
    end
    ActionController::MissingTemplate: Missing template ../app/views/dummy/song_search.rhtml

    I'm sure it's something obvious I'm missing but I'm just not seeing it.

    Thanks for any help,
    Clem
    Last edited by clem_c_rock; Nov 17, 2007 at 10:06.

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shouldn't the line:
    Code:
    @controller = DummyController.new
    be
    Code:
    @controller = DummyClass.new

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're right - typo on my part - fixed

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, does that mean your problem is solved, or that you have fixed a typo in your original post and the problem still exists?

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    NC
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No the problem still exist. My code was a simplified version of the code I'm writing.

    That was just a typo.

    wish that was the fix

  6. #6
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I also think the line:
    Code:
    class ParentControllerTest < Test::Unit::TestCase
    may need to be:
    Code:
    class DummyControllerTest < Test::Unit::TestCase
    I think what you are doing will work. However, you will need to create more than just a new controller class. If you create DummyController, you will also need to create an app/views/dummy folder containing the views for each of the methods. Alternatively, you need a way to force actions in the dummy version of the controller to render the parent's views (an ugly way would be to use render in each of the parent controller methods - I'm sure there is probably a neater way to do it). Your error message:
    Code:
    Missing template ../app/views/dummy/song_search.rhtml
    suggests to me that this is where your problem lies.

    You'll also need to manually create your fixtures and tests, but your post suggests you are already working on that.

    If you are using this technique to share some common controller methods with a number of controllers, it would be worth considering using a module or mixin rather than inheritance.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •