Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Including Static HTML Snippet

In Ruby on Rails, can we have some GLOBAL static HTML snippets that we can use in the same way as a helper just like include in php? I'm making a nav bar but sometimes I want it at the bottom of my page.

Thanks in advance.

like image 838
Guanlun Avatar asked Dec 06 '25 13:12

Guanlun


1 Answers

You can use partials:

Create a view which its filename starts with an underscore, for example: /views/shared/_navbar.html.erb

then you can render this partial anywhere you'd like using

<%= render :partial => "shared/navbar" %>

in your view.

Note that although the partial file name has an underscore in the beginning, the render states its name with the underscore omitted.

like image 79
Erez Rabih Avatar answered Dec 11 '25 05:12

Erez Rabih



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!