Calling HTML snippet from another HTML file

20 views
Skip to first unread message

Damián M. González

unread,
Jun 13, 2014, 7:34:43 AM6/13/14
to rubyonra...@googlegroups.com
Hi guys. I'm relatively new to rails, not to ruby. Was wondering how can
I call an HTML file(perhaps *.erb.html) from another HTML file. I'm
writing HTML in the application layout(application.html.erb) and I want
to abstract some parts like the footer and the upper part to another
file, for easy reading and order. My clue is to call render() to each
file(footer and upper), but is that fine? Do you use another way to do
this? can sugget me? Thank you.

--
Posted via http://www.ruby-forum.com/.

Ganesh Ranganathan

unread,
Jun 13, 2014, 7:53:23 AM6/13/14
to rubyonra...@googlegroups.com

On Fri, Jun 13, 2014 at 5:03 PM, Damián M. González <li...@ruby-forum.com> wrote:
I want
to abstract some parts like the footer and the upper part to another
file, for easy reading and order.

​This can be achieved by layouts. In the layouts/application.html.erb file you can call different partial views using the render keyword

<%= render 'layouts/sidebar' %> 

The sidebar code can be in a file called  _sidebar.html.erb in the layouts folder. The underscore is rails convention

Thanks,
Ganesh​

Colin Law

unread,
Jun 13, 2014, 8:23:12 AM6/13/14
to rubyonra...@googlegroups.com
As a newcomer to Rails I suggest you work right through a good
tutorial such as railstutorial.org. That will show you the basics
including how to use partials, which is what you are looking for.

Colin

Damián M. González

unread,
Jun 13, 2014, 10:14:18 AM6/13/14
to rubyonra...@googlegroups.com
Thank you Ganesh and Colin for the answers, very accurated. I really
apreciate it.
Reply all
Reply to author
Forward
0 new messages