$ rails s -e production
or
$ RAILS_ENV=production rails s
or
$ export RAILS_ENV=production
$ printevn | grep RAILS_ENV
$ rails s
If you have already instantiated any objects, their attributes would not be updated - including newly introduced validations. However, if you create a new object, its attributes (and also validations) will reflect the reloaded code.
$ rails console
> reload!
# rails intall
gem install rails -v 6.0.2
rails _6.0.2_ new appname
# without the default testing suite:
rails new appname -T
# skip turbolinks:
rails new appname --skip-turbolinks
# database
rails new appname --database=postgresql
# help
rails new -h
config/credentials.yml.enc
is an encrypted file which store the credentials. As this is a encrypted file, we can safely commit it to our version control systems.
config/master.key
contains RAILS_MASTER_KEY which is used to decrypt the config/credentials.yml.enc. We should not commit this file to version control
$ EDITOR="atom --wait" rails credentials:edit
for multi environment credentials
$ EDITOR="atom --wait" rails credentials:edit --environment development
The secret key base is required by Rails. If you want to generate a new secret key base run,
$ bin/rails secret
and add that to your credentials by running bin/rails credentials:edit
.
Turbolinks makes following links in your web application faster. Instead of letting the browser recompile the JavaScript and CSS between each page change, it keeps the current page instance alive and replaces only the body (or parts of) and the title in the head. Think CGI vs persistent process.\
document.addEventListener("turbolinks:load", function() {
// ...
})
- https://withrails.com/2016/01/01/%ED%84%B0%EB%B3%B4%EB%A7%81%ED%81%ACturbolinks-%EC%9D%B4%ED%95%B4%ED%95%98%EA%B8%B0/
- https://coderwall.com/p/ypzfdw/faster-page-loads-with-turbolinks
- Browsers natively only support HTTP GET and POST methods, we have to do something a bit tricky to use HTTP POST to fake
PUT/PATCH/DELETE
methods. - On the server side, Rails is able to examine the
_method
value in the params to restore the semantics of the HTTP request.
<form method="post" action="/posts/<%= post.id %>" style='display: inline'>
<input name= "_method" type="hidden" value="delete">
<input type="submit" value="Delete" />
</form>
resource does not have an index method, as it is supposed to be only for a single resource
/workshop
resource: new, create, show, edit, update, destroy
/workshops/:id
resources: index, new, create, show, edit, update, destroy
moduleActionView
class Base
cattr_accessor :field_error_proc
@@field_error_proc = Proc.new{ |html_tag, instance|
"<div class=\"field_with_errors\">#{html_tag}</div>".html_safe
}
end
...
# we can customize it
ActionView::Base.field_error_proc = proc do |html_tag, instance|
include FormHelper
FormHelper.error_message(html_tag, instance)
end
module FormHelper
include ActionView::Context
include ActionView::Helpers::TextHelper
include ActionView::Helpers::TagHelper
def error_message(html_tag, instance)
output = content_tag(:div, class: "form__field--error") do
concat html_tag.html_safe # rubocop:disable Rails/OutputSafety
unless html_tag.match?(/^<label/)
concat content_tag(:label, instance.error_message.any? ? instance.error_message.first : "",
class: ["message", "form__error"], for: instance.send(:tag_id))
end
end
return output if output.html_safe?
end
end