I'm not sure if this is convention or not, but I have been working through Hartl's Rails tutorial and I noticed that he creates all his partial files with a leading underscore. For example _user.html.erb. Is this something that is necessary for the partial to work, or is this a stylistic choice?
It's necessary for partials to work. From the official Rails guide:
3.4.1 Naming Partials
To render a partial as part of a view, you use the render method within the view:
<%= render "menu" %>This will render a file named _menu.html.erb at that point within the view being rendered. Note the leading underscore character: partials are named with a leading underscore to distinguish them from regular views, even though they are referred to without the underscore. This holds true even when you're pulling in a partial from another folder:
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