When creating an app with Rails
, I've put together some code that I found useful in the early stages of creation (for myself).
Ruby on Rails
% rails _6.0.0_ new 'file name' -d mysql
config/database.yml
# encoding: utf8mb4
=> encoding: utf8
I can't explain in detail yet, but if it remains utf8mb4
, it cannot be migrated well due to the number of bytes.
Please refer to here for the correspondence when creating a database with utf8mb4
.
【MySQL】Mysql2::Error: Specified key was too long; max key length is 767 bytes
% rails db:drop
% rails db:create
gemfile.rb
gem 'devise' #Implementation of user registration function
gem 'mysql2', '>= 0.5.3' #Change mysql version
gem 'pry-rails' #Used when checking for errors and testing
gem 'mini_magick' #Gem for using ImageMagick
gem 'image_processing' #Gem to adjust image size
gem 'active_hash' #A gem that is convenient when dealing with static data such as prefectures
The browser has CSS
set by default, so apply it to reset it.
app/views/layouts/application.html
<head>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.18.1/build/cssreset/cssreset-min.css">
</head>
If you leave nothing set, when you set padding
or border
with CSS
, it may become an unintended size, so set it so that it has the desired element size.
application.css
* {
box-sizing: border-box;
}
devise
% rails g devise:install
% rails g devise user
% rails g devise:views
% rails db:migrate
controller.rb
before_action :authenticate_user!, except: [:index, :show]
email
and password
set in devise
to be usedapp/controllers/application_controller.rb
before_action :configure_permitted_parameters, if: :devise_controller?
private
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:])
end
Recommended Posts