# How to use templates in ruby

**URL:** <https://www.ruby-forum.com/t/how-to-use-templates-in-ruby/161931>\
**Category:** Rails\
**Created:** [March 3, 2009, 11:41pm UTC](https://www.ruby-forum.com/t/how-to-use-templates-in-ruby/161931 "2009-03-03T23:41:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [March 3, 2009, 11:41pm UTC](https://www.ruby-forum.com/t/how-to-use-templates-in-ruby/161931/1 "2009-03-03T23:41:01Z")

</div>

hi all,

I have created links ie:-

/articles  
/news

and i looked on a site and it said creating a .rhtml file in the  
app/views/articles news etc but when i created news.rhtml and  
articles.rhtml and put it in the folder in the app/views and its still  
reading the

class ArticlesController \< ApplicationController  
def index  
render :text =\> “This is the articles page”  
end

end

in the controller and not the .rhtml file

how is this done

many thanks

paul

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [March 4, 2009, 11:05am UTC](https://www.ruby-forum.com/t/how-to-use-templates-in-ruby/161931/2 "2009-03-04T11:05:52Z")

</div>

On Wed, Mar 4, 2009 at 11:01 AM, Peter V.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If I understand correctly, the fact that you call render explicitely  
> in the controller, will avoid the “automatic” render of the template in  
> app/views/articles/index.html.erb

Forgot to explain this. Only if you did not explicitly call ‘render’  
or ‘redirect\_to’  
Rails will automatically call the render function on the corresponding  
location  
in the …/app/views/ directory.

Peter

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [March 4, 2009, 11:02am UTC](https://www.ruby-forum.com/t/how-to-use-templates-in-ruby/161931/3 "2009-03-04T11:02:55Z")

</div>

On Tue, Mar 3, 2009 at 11:41 PM, Paul Na  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> articles.rhtml and put it in the folder in the app/views and its still
> 
> how is this done

If I understand correctly, the fact that you call render explicitely  
in the controller,  
will avoid the “automatic” render of the template in  
app/views/articles/index.html.erb

So, I suggest yoiu change as follows:

Controller: …/app/controllers/articles\_controller.rb

class ArticlesController \< ApplicationController  
def index  
@test\_article = “This is a test article”  
end  
end

Views: …/app/views/articles/index.html.erb

test of an article \<%=h @test\_article %\>

Then go to

htpp://localhost:3000/articles/

HTH,

Peter

> many thanks
> 
> ## paul
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Peter V.  
gsm: +32-478-27.40.69  
e-mail: removed\_email\_address@domain.invalid  
[http://www.linkedin.com/in/petervandenabeele](http://www.linkedin.com/in/petervandenabeele)  
[http://vandenabeele.com](http://vandenabeele.com)  
[http://twitter.com/peter\_v](http://twitter.com/peter_v)

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [March 4, 2009, 12:02pm UTC](https://www.ruby-forum.com/t/how-to-use-templates-in-ruby/161931/4 "2009-03-04T12:02:23Z")

</div>

Peter V. wrote:

> On Wed, Mar 4, 2009 at 11:01 AM, Peter V.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > If I understand correctly, the fact that you call render explicitely  
> > in the controller, will avoid the “automatic” render of the template in  
> > app/views/articles/index.html.erb
> 
> Forgot to explain this. Only if you did not explicitly call ‘render’  
> or ‘redirect\_to’  
> Rails will automatically call the render function on the corresponding  
> location  
> in the …/app/views/ directory.
> 
> Peter

Hi peter

Thanks its working , Im just trying to get my head around it all.

Thanks again

Paul

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [March 4, 2009, 4:12pm UTC](https://www.ruby-forum.com/t/how-to-use-templates-in-ruby/161931/5 "2009-03-04T16:12:15Z")

</div>

Paul Na wrote:

> Thanks its working , Im just trying to get my head around it all.

By the way in case you didn’t notice, all the cool kids are using the  
“html.erb” extension instead of “rhtml” extension for view templates  
that render HTML using embedded Ruby (ERB).

I’ll leave it as a task for you to discover why html.erb is so cool.

---

<div class="post-metadata">

**Author:** ![nanouk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/da6949/32.png) [@nanouk](https://www.ruby-forum.com/u/nanouk)\
**Post date:** [March 4, 2009, 5:24pm UTC](https://www.ruby-forum.com/t/how-to-use-templates-in-ruby/161931/6 "2009-03-04T17:24:21Z")

</div>

Robert W. wrote:

> Paul Na wrote:
> 
> > Thanks its working , Im just trying to get my head around it all.
> 
> By the way in case you didn’t notice, all the cool kids are using the  
> “html.erb” extension instead of “rhtml” extension for view templates  
> that render HTML using embedded Ruby (ERB).
> 
> I’ll leave it as a task for you to discover why html.erb is so cool.

Hi robert

yeh i did come across soething to do with it when trying to load the  
news page up and it come back with a error , which i had the news page  
as index.rhtml.erb i changed it to index.html.erb then it worked
