The next_rails_scaffold gem is a powerful extension to the standard Ruby on Rails scaffold generator.
The next_rails_scaffold
gem is a powerful extension to the standard Ruby on Rails scaffold generator. It streamlines the development workflow by not only creating the backend structure with Rails but also automating the setup of a frontend directory using Next.js. Upon running the scaffold generator, this gem intelligently generates a Next.js application within the specified frontend directory.
The generated Next.js app follows best practices, including a structured page routing system, ensuring that each resource created by the scaffold has its corresponding page and components. This integration enables developers to seamlessly transition between Rails backend and Next.js frontend development, fostering a cohesive and efficient development environment.
Currently, https://www.hygen.io/ is used to create Next.js code, and the https://github.com/raphox/next-rails-scaffold repository contains template files.
In one of my posts on Medium I go into more detail about the reasons why I created this project. But to summarize, I’ll list a few relevant points:
Integrate next_rails_scaffold
into your Ruby on Rails projects to enjoy a streamlined, organized, and efficient full-stack development experience.
Install the gem and add to the application’s Gemfile by executing:
$ bundle add next_rails_scaffold
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install next_rails_scaffold
The next_rails_scaffold
gem enhances the default Ruby on Rails scaffold generator by seamlessly integrating with Next.js, a React framework. This gem automates the process of scaffolding a Rails application along with a corresponding frontend directory containing a Next.js application. The generated Next.js app includes all necessary pages and components, leveraging the power of page routing for a smooth and organized development experience.
Example:
# Appending the `next_rails_scaffold` generator steps to the to the Rails' scaffold generator.
bin/rails generate next_rails_scaffold:install
# Generate the RESfull API endpoints and Next.js app with respective components and pages.
bin/rails generate scaffold Post title:string body:text
This will create:
app/
controllers/
posts_controller.rb
models/
post.rb
...
frontend/
src
components
Post.js
PostForm.js
pages
posts
[id]
edit.js
index.js
index.js
new.js
providers.js
services.js
Sample app https://github.com/raphox/next-rails-app.
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/raphox/next_rails_scaffold.
The gem is available as open source under the terms of the MIT License.