可以:环境在sinatra的路线声明中用作条件吗?

时间:2022-06-05 23:18:37

Im trying to create a route that is only available for :development for example:

我试图创建一个仅适用于:开发的路线,例如:

get '/logs', :environment => :development do
    #dump logs
end

This does not work, any ideas? Thanks :)

这不起作用,任何想法?谢谢 :)

2 个解决方案

#1


4  

You could create your own condition to check the environment:

您可以创建自己的条件来检查环境:

set(:check_env) {|value| condition{value == settings.environment}}

get '/logs', :check_env => :development do
  #dump logs
end

Another, possibly simpler, option would be to only create the route in development:

另一个可能更简单的选择是仅在开发中创建路径:

configure :development do
  get '/logs' do
    #dump logs
  end
end

#2


1  

get '/logs' if ENV['RACK_ENV'] == 'development'

should work

应该管用

#1


4  

You could create your own condition to check the environment:

您可以创建自己的条件来检查环境:

set(:check_env) {|value| condition{value == settings.environment}}

get '/logs', :check_env => :development do
  #dump logs
end

Another, possibly simpler, option would be to only create the route in development:

另一个可能更简单的选择是仅在开发中创建路径:

configure :development do
  get '/logs' do
    #dump logs
  end
end

#2


1  

get '/logs' if ENV['RACK_ENV'] == 'development'

should work

应该管用