John
2012-Dec-03 20:36 UTC
Can not render pre designed html template from public directory
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. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <link href="css/style.css" rel="stylesheet" type="text/css" media="all"/> </head> <body> <div class="title">Post: *{post_name}*</div> </body> </html> 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/{....} I will be pleased if anyone can help me regarding this. Thanks in advance for your help. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/fDz8pt0SKZgJ. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2012-Dec-04 09:29 UTC
Re: Can not render pre designed html template from public directory
On 3 December 2012 20:36, John <mr.johnamato-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > <html xmlns="http://www.w3.org/1999/xhtml"> > <head> > <meta http-equiv="Content-Type" content="text/html; > charset=iso-8859-1"/> > <link href="css/style.css" rel="stylesheet" type="text/css" > media="all"/> > </head> > <body> > <div class="title">Post: {post_name}</div> > </body> > </html> > > 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/{....}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 (which is free to use online) so that you will understand the basics of rails. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
dasibre
2012-Dec-04 21:23 UTC
Re: Can not render pre designed html template from public directory
As Colin Law 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) On Monday, December 3, 2012 3:36:00 PM UTC-5, John wrote:> > 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. > > <html xmlns="http://www.w3.org/1999/xhtml"> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> > <link href="css/style.css" rel="stylesheet" type="text/css" media="all"/> > </head> > <body> > <div class="title">Post: *{post_name}*</div> > </body> > </html> > > 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/{....} > > I will be pleased if anyone can help me regarding this. Thanks in advance for your help. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/VJ4zv9o6gw4J. For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2012-Dec-04 23:56 UTC
Re: Can not render pre designed html template from public directory
On Dec 3, 4:36 pm, John <mr.johnam...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> <html xmlns="http://www.w3.org/1999/xhtml"> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> > <link href="css/style.css" rel="stylesheet" type="text/css" media="all"/> > </head> > <body> > <div class="title">Post: *{post_name}*</div> > </body> > </html> > > 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> I will be pleased if anyone can help me regarding this. Thanks in advance for your help.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.