One controller rendering using another controller's views

前端 未结 4 1371
渐次进展
渐次进展 2020-12-14 06:07

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

4条回答
  •  旧巷少年郎
    2020-12-14 07:07

    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' %> 
    

提交回复
热议问题