Using High Voltage to Serve Static Page Without Database and Controller in Rails App
When we create an app that provide some static pages, sometimes we use a resource called Page, save it in the table and call it from controller. Now, we have an alternative to make it without a database even without a controller by using High Voltage
Add high_voltage gem to your Gemfile
gem 'high_voltage', '~> 2.2.1'
After that, create a directory in your views called pages
app/views/pages
And then create your desired view in this directory, for example I want to create an about us page here, I create a file about.html.erb
and fill html content here.
I can create a link to your page by using this
link_to 'About Us', page_path('about')
.
about
is the page that I have created before, this will generate url like this http://localhost:3000/pages/about.
And Done!!