Rails 5.0 was released just some eight months ago, and now, some 3500 commits later, we’re already close to the next big release. And what release this version 5.1 is lining up to be! We’ve made great strides on long-term promises and key ergonomics while also spring cleaning a bunch of deprecated code.
rails new project_name --webpack
;Capybara 默认引入,增加 ApplicationSystemTestCase
类型:
class Users::CreateTest < ApplicationSystemTestCase
test "adding a new user" do
visit users_path
click_on 'New User'
fill_in 'Name', with: 'Arya'
click_on 'Create User'
assert_text 'Arya'
end
end
似乎不太感兴趣,一直没这么写测试...
看起来是为了解决 secrets 总会无意中被带入版本管理里面,成为安全漏洞的问题。
于是 config/secrets.yml
现在起将变成加密的内容,在项目初始化的时候会有一个 key
(私钥),独立保存 key
,然后 config/secrets.yml
就可以放心放入版本库了。
以后编辑 secrets 需要执行 rails secrets:edit
。
production
环境的时候需要用私钥才能读取,或者配置环境变量 RAILS_MASTER_KEY=xxxx
。
也就是说以后那些各类需要保密用的私钥,例如 OAuth 2 的 key、三方平台的秘钥、密码加密的 salt 什么的都可以统统放入 config/secrets.yml
里面统一管理。
https://github.com/rails/rails/blob/master/railties/lib/rails/commands/secrets/USAGE
看起来大致就是 ActionMailer 编写可以支持 before_action
了 rails/rails/actionmailer/lib/action_mailer/parameterized.rb#2dadf73:
class InvitationsMailer < ApplicationMailer
before_action { @inviter, @invitee = params[:inviter], params[:invitee] }
before_action { @account = params[:inviter].account }
default to: -> { @invitee.email_address },
from: -> { common_address(@inviter) },
reply_to: -> { @inviter.email_address_with_name }
def account_invitation
mail subject: "#{@inviter.name} invited you to their Basecamp (#{@account.name})"
end
end
看起来是一个很大的改动,routes.rb 新增 direct
和 resolve
DSL:
# config/routes.rb
resource :profile
namespace :admin do
resources :users
end
direct(:apple) { "http://www.apple.com" }
resolve("User") { [:profile] }
direct(class: "User") { [:profile] }
# resolve 的效果
app_url # http://www.apple.com
<%= form_for @user do |form| %>
<% end %>
# <form action="/profile/1"></form>
# 然后 View 里面使用 link_to 会有这样的结果
link_to 'Profile', @uesr # /profile
link_to 'Profile', [:admin, @uesr] # /admin/users/1
form_with
https://github.com/rails/rails/issues/25197