Standardize MVC structure for database-backed web app development
You can start with the model, view, and controller structure required for building websites connected to a database. Written in Ruby, this framework standardizes the process of treating database rows as objects, rendering HTML templates, and handling HTTP requests. This allows developers to focus on business logic without building the basic structure from scratch.
The three layers of the MVC pattern
Rails divides the application into model, view, and controller parts to clarify their respective responsibilities. The model layer inherits from ActiveRecord::Base to represent database data as objects and include business logic. The view layer uses Action View to render ERB templates mixing HTML and Ruby code to create screens for users. The controller layer uses Action Dispatch and Action Controller to receive incoming HTTP requests, manipulate models, and return appropriate responses.
Core libraries provided
In addition to the basic MVC structure, Rails provides features frequently needed for web development as separate libraries.
- Email handling Action Mailer handles email creation and sending, while Action Mailbox handles receiving.
- Background jobs Active Job declares jobs to be executed on various queuing backends.
- Real-time communication Action Cable integrates websockets into Rails applications.
- File management Active Storage attaches cloud or local files to the application.
Process to first run
To get started, install Rails in the terminal with the gem install rails command. Then create a new application with the rails new myapp command, move to that directory, and run bin/rails server. Once the server starts, visiting http://localhost:3000 in the browser displays the Rails boot screen and the current Rails and Ruby versions in use. Once this step is complete, the basic environment for development is ready.
Individual module usage and contribution guide
Active Record, Active Model, Action Pack, and Action View can be used individually, not just as part of the whole Rails framework. This means they can be applied flexibly when only specific parts of Rails are needed. When participating in the project or reporting bugs, follow Rails' contribution guide and security policy, and all interactions must comply with the Rails Code of Conduct. The license is MIT, allowing commercial use.