[RUBY] [Rails] New app creation --Notes--

Create new app

After moving to the directory you want to create

Terminal


rails new [app name] -d mysql

Specify mysql when creating database with "-d mysql"

Database creation

Move to the created app directory. The following command will create the database according to the settings described in database.yml.

Terminal


rake db:create

If it doesn't work as expected, check database.yml. Since sqlite is specified in the initial database, if necessary, write mysql in gem and bundle install.

Reference: Let's develop Rails applications! ~ Development Preparation ~

Creating a controller

Terminal


rails g controller [Controller name]

Routing settings

routes.rb


root "[Controller name]#index"

When root accesses with url, the controller and action displayed on the top page are displayed. This time, the [index] action is specified.

Controller action description

I will describe the necessary actions.

[Controller name]_controller.rb


def index
end

View file creation

Since the [app/views/controller name /] directory has been created, create the index.html.erb file.

html:index.html.erb


<p>Hello, World!</p>

Here, when you start the rails server and access it locally, "Hello, World!" Is displayed.

Create table

Terminal


rails g model [Model name]

When you create a model, a migration file for creating a table is automatically generated. Describe the migration file and execute the migration file.

Terminal


rails db:migrate

Reference Active Record Migration Reference Rails Migration Basic Summary

that's all.

Recommended Posts

[Rails] New app creation --Notes--
[Rails6] Create a new app with Rails [Beginner]
[Rails] Many-to-many creation
Ruby on Rails application new creation command
[Rails 5] Create a new app with Rails [Beginner]
html & rails notes
rails new app is not created with app name
Rails Tutorial Chapter 5 Notes
Rails Tutorial Chapter 10 Notes
Rails Tutorial Chapter 3 Notes
Heroku app moving (rails)
Rails Tutorial Chapter 4 Notes
Rails Tutorial Chapter 8 Notes
rails tutorial fighting notes Ⅲ
Nuxt.js x Rails app creation CORS policy Error resolution
[Rails] Launch a new project
rails new application launch command
Portfolio creation Ruby on Rails
API creation with Rails + GraphQL
Rails reference type creation added
Incorporate circleCI into CircleCI Rails app
App creation comment function asynchronous
Incorporate Elasticsearch into your Rails app
Add & save from rails database creation
Rails book review app RSpec introduction
[Rails] Creating a new project with rails new
[Rails] How to add new pages
[Rails] Initial data creation with seed
Notes on calling Installer on Android App
[Ruby on Rails] Confirmation page creation
Track Rails app errors with Sentry
Deploy your Rails app on Heroku