Personal like Ruby
Please let me know if you make a mistake.
AWS Cloud9
It's basically the same as Laravel, and it seems that the idea of MVC is okay.
$ gem install rails -v 5.2.4
$ rails new app_name
Controller name is plural as much as possible Mostly plural
Location ~ / home / ec2-user / environment / app name / app / controllers
$rails g controller controller name
$rails g controller controller name action name
$ rails g controller todolists home
$rails d controller controller name
The way of thinking about routing is the same as Laravel
A place like a command room that controls pretty much anything
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
get 'home' => 'tops#home'
#When you come to home with the URL, take the home action of the tops controller! Means
end
All you have to do is create the file (home.html.erb) specified earlier in the ~ / app / view / name.
I have no choice but to do my best for html and other UI
Either of the following
$ rails server
$ rails s
I will summarize the error messages someday.
A great guy who can instantly connect with database related things.
Check it out for more details (because it's the real thrill of the framework)
$rails g model model name
Singular, first uppercase
OK if 4 files appear
It ’s already familiar in Laravel.
I will put a template-like one
class CreateLists < ActiveRecord::Migration[5.2]
def change
create_table :lists do |t|
t.string :name
t.string :contents
t.timestamps
end
end
end
A spell to reflect what is in the migration file in the database
$ rails db:migrate
$rails g migration Add Column name To Table name Column name:Model name
$rails g migration AddIdToLists Id:int
$rails g migration Remove Column name From table name Column name:Model name
$rails g migration RemoveIdFromLists Id:int
Well, it's easy to understand if you think about English
But I thought after doing so far. Did you create a database? ?? That?
When I looked it up later, it seems that Ruby on Rails uses SQLite by default instead of the MySQL I usually use ... (I couldn't find it even if I searched for Mysql reasonably).
By the way, the database is
$rake db:create
It seems that this can be done
However, there are still many mysteries, and the momentum was too much ...?
I will update it from time to time.
Recommended Posts