Forum: Ruby on Rails Calling HTML snippet from another HTML file

5b972395a92333843018b4add8af0437?d=identicon&s=25 Damián M. González (igorjorobus)
on 2014-06-13 13:33
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.
61b2cb27fe3d25f42ecc0364c33420f8?d=identicon&s=25 Ganesh Ranganathan (Guest)
on 2014-06-13 13:54
(Received via mailing list)
On Fri, Jun 13, 2014 at 5:03 PM, Damián M. González
<lists@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​
4c6bde00168d595053c09aac7e487f8e?d=identicon&s=25 Colin Law (Guest)
on 2014-06-13 14:24
(Received via mailing list)
On 13 June 2014 12:33, Damián M. González <lists@ruby-forum.com> wrote:
> 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.

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
5b972395a92333843018b4add8af0437?d=identicon&s=25 Damián M. González (igorjorobus)
on 2014-06-13 16:13
Thank you Ganesh and Colin for the answers, very accurated. I really
apreciate it.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.