Rails rails 能通过 env 控制 routes 吗

tomanderson · November 13, 2021 · Last by yuchiXiong replied at November 14, 2021 · 500 hits

比如我在 routes.rb 有一条 route,我想当 env=production 的时候启用它,env=development 的时候禁用他,有办法做到吗?

#routes.rb
if Rails.env.production? do
  resources :blogs
end
Reply to yuchiXiong

报错啊,启动不了。换成 if-then 启动了

Reply to yuchiXiong

去掉 do 就行了。

Reply to Rei

有段时间没写 ruby 了……忘了 hhh😂

You need to Sign in before reply, if you don't have an account, please Sign up first.