# Can not render pre designed html template from public directory

**URL:** <https://www.ruby-forum.com/t/can-not-render-pre-designed-html-template-from-public-directory/226470>\
**Category:** Rails\
**Created:** [December 4, 2012, 12:01am UTC](https://www.ruby-forum.com/t/can-not-render-pre-designed-html-template-from-public-directory/226470 "2012-12-04T00:01:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [December 4, 2012, 12:01am UTC](https://www.ruby-forum.com/t/can-not-render-pre-designed-html-template-from-public-directory/226470/1 "2012-12-04T00:01:44Z")

</div>

Hello,  
I have a designed template _public/test/show.html_ with following sample  
html code. There is a css file and images in the mentioned directory.

Post: \*{post\_name}\*

I have a posts controller and need to render this template from  
posts#show without changing anything under \*public/test \*directory. And,  
replace _{post\_name}_  
by post name.

I’ve tried that in many ways to do that but couldn’t. Specially, the css  
and images path not working any way. It’s always looking under  
[http://localhost:3000/posts/{....}](http://localhost:3000/posts/%7B....%7D)

I will be pleased if anyone can help me regarding this. Thanks in  
advance for your help.

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [December 4, 2012, 10:31am UTC](https://www.ruby-forum.com/t/can-not-render-pre-designed-html-template-from-public-directory/226470/2 "2012-12-04T10:31:39Z")

</div>

On 3 December 2012 20:36, John [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I've tried that in many ways to do that but couldn't. Specially, the css and images path not working any way. It's always looking under http://localhost:3000/posts/{....}

I am not sure what you are trying to do exactly but I think your whole  
approach is probably wrong, it is certainly not conventional. I  
suggest you work right through a good tutorial such as  
[railstutorial.org](http://railstutorial.org) (which is free to use online) so that you will  
understand the basics of rails.

Colin

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [December 4, 2012, 10:25pm UTC](https://www.ruby-forum.com/t/can-not-render-pre-designed-html-template-from-public-directory/226470/3 "2012-12-04T22:25:04Z")

</div>

As Colin L. stated you are not following the Rules of Rails. Why do you  
want to put a template in the public folder and create a headache for  
yourself. I suggest doing it the Rails way. Put your templates in  
/view/controller/show.html.erb  
Your basic controller actions CRUD, have corresponding views(template)

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [December 5, 2012, 12:58am UTC](https://www.ruby-forum.com/t/can-not-render-pre-designed-html-template-from-public-directory/226470/4 "2012-12-05T00:58:42Z")

</div>

On Dec 3, 4:36pm, John [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a posts controller and need to render this template from posts#show  
> without changing anything under \*public/test \*directory. And, replace  
> _{post\_name}_  
> by post name.
> 
> I’ve tried that in many ways to do that but couldn’t. Specially, the css and  
> images path not working any way. It’s always looking  
> underhttp://localhost:3000/posts/{…}

Your CSS link is relative (doesn’t begin with a / ) so the browser  
will think the path for it is /posts/test/css/style.css.

Making the css and any asset links absolute will fix this. You could  
if you really didn’t want to change the file, add a route for that  
path and render the css file in response but that seems a bit over the  
top. Alternatively rewrite any of those relative links in the file  
before you send the response (I’d recommend using nokogiri to do this  
rather than tearing apart the HTML with regular expressions). I’m also  
sure why this isn’t a regular erb/haml template though instead of  
inventing your own templating scheme.

Fred
