# How to define default template path in controller

**URL:** <https://www.ruby-forum.com/t/how-to-define-default-template-path-in-controller/142901>\
**Category:** Rails\
**Created:** [July 13, 2008, 1:57am UTC](https://www.ruby-forum.com/t/how-to-define-default-template-path-in-controller/142901 "2008-07-13T01:57:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gsterndale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@gsterndale](https://www.ruby-forum.com/u/gsterndale)\
**Post date:** [July 13, 2008, 1:57am UTC](https://www.ruby-forum.com/t/how-to-define-default-template-path-in-controller/142901/1 "2008-07-13T01:57:38Z")

</div>

StudentsController extendeds my basic RESTful UsersController. Student  
is a named\_scope in my User model.

I’d like the students controller to render templates in app/views/  
users/, not app/views/students/. How can I do this DRYly without  
redefining all the methods in UsersController?

# entire students\_controller.rb

class StudentsController \< UsersController  
protected  
def find\_users  
@users = User.student.find(:all)  
end  
def find\_user  
@user = User.student.find(params[:id])  
end  
end

# relevant parts of users\_controller.rb

class UsersController \< ApplicationController  
before\_filter :find\_users, :only =\> [:index]  
def index  
respond\_to do |format|  
format.html # index.html.erb  
format.xml { render :xml =\> @users }  
end  
end  
#… other REST methods  
protected  
def find\_users  
@users = User.find(:all)  
end  
def find\_user  
@user = User.find(params[:id])  
end  
end

When I GET /students…  
Template is missing  
Missing template students/index.html.erb in view path /Path/To/MyApp/  
app/views

In StudentsController I tried: append\_view\_path("/Path/To/MyApp/app/  
views/users")…  
Template is missing  
Missing template students/index.html.erb in view path /Path/To/MyApp/  
app/views:/Path/To/MyApp/app/views/users

Any ideas? Is there a better approach entirely? Perhaps some magic  
routing?

Thanks!

---

<div class="post-metadata">

**Author:** ![gsterndale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@gsterndale](https://www.ruby-forum.com/u/gsterndale)\
**Post date:** [July 16, 2008, 12:05pm UTC](https://www.ruby-forum.com/t/how-to-define-default-template-path-in-controller/142901/2 "2008-07-16T12:05:46Z")

</div>

Hi,

Anyone have used the “html to pdf convertors” on ruby.

Thanks in Advance,  
Usha

---

<div class="post-metadata">

**Author:** ![gsterndale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@gsterndale](https://www.ruby-forum.com/u/gsterndale)\
**Post date:** [July 16, 2008, 12:08pm UTC](https://www.ruby-forum.com/t/how-to-define-default-template-path-in-controller/142901/3 "2008-07-16T12:08:07Z")

</div>

Sorry wrong message, Please forgive for the inconvenience.
