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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With