Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have QuestionController I now have AnotherQuestionController with actions which should render using templates and partials in app/views/question/ Is this possible? Seems like it should be.

I've tried

render :template => "question/answer"

but answer.html.erb includes partials and I get errors like

"Missing template another_question/_my_partial.erb in view path"

So is there a way to tell Rails "treat AnotherQuestionController as if its QuestionController and look for views and partials in app/views/question"? Or will I have to create app/views/another_question - which will cause duplication (this can't be the Rails way).

Thanks

share|improve this question

3 Answers

Template rendering should actually work

 render :template => "question/answer"

The problem you were having is from the partials looking in the wrong place. The fix is simple, just make your partials absolute in any shared templates. For example, question/answer.html.erb should have

<%= render :partial => 'question/some_partial' %>

rather than the usual

<%= render :partial => 'some_partial' %>
share|improve this answer
This did not work I'm afraid – Paul Jun 19 '09 at 11:50
oh right. On second examination I've found the actual issue – Ben Hughes Jun 19 '09 at 14:21
Any new way of doing this in rails 3.x? I'm asking because I'm using a gem which gives helpers to automatically do the rendering in the view (otherwise your solution would work). I would rather not overwrite the that gem's helpers. Thanks! – montrealmike Oct 28 '11 at 15:22

You can achieve it with:

render 'question/answer'
share|improve this answer

You could try the inherit_views plugin (http://github.com/ianwhite/inherit_views/tree/master) I mentioned here in the answer to this question.

share|improve this answer
Thanks, I'll look into this. Seems like a lot of work though doesn't it. I would have thought render() would have taken options allowing to specify another controller's views/partials. Ah well. – Paul Jun 19 '09 at 11:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.