将路线添加到仪表板 [英] Add routes to Dashing dashboard

查看:92
本文介绍了将路线添加到仪表板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在仪表板中添加我可以访问的路线,例如...

How do I add a route in my dashboard that I can access, for example...

get '/:id' do
  protected!
  return params[:'id']
end

我可以打电话给我来自 http:// localhost:3030?id = 1234

Which I can call from http://localhost:3030?id=1234

推荐答案

最简单的方法是定义一个新应用程序,并在 config.ru 中调用它由Dashing创建。例如,我在一个带有以下内容的虚线仓库中创建了一个名为 my_app.rb 的新文件:

The easiest way to do this would be to define a new application and call it inside the config.ru that gets created by Dashing. For instance, I created a new file called my_app.rb in a dashing repo with the following contents:

# my_app.rb

require 'sinatra/base'

class MyApp < Sinatra::Base
  get '/:id' do
    "My own custom route! And the id is #{params[:id]}"
  end
end

并将该应用包含在 config.ru 之内所以:

And included that app inside the config.ru like so:

# Created by dashing until Sinatra::Application
…
run Sinatra::Application

# added by us
run MyApp

然后当您运行破折号开始,我们在应用中定义的路由就会被调用。但是这种方法存在一个问题,那就是您需要确保在 MyApp 中定义的路由不会与已经通过虚线定义的路由冲突。解决此问题的另一种方法是让破折号在默认 / 以外的路径上运行。有一些此文档Wiki中的方法

And then when you run dashing start, the route we defined in our app gets called. But there's a problem with this approach in that you need to ensure that the routes being defined in MyApp won't conflict with those already defined by dashing. The other way to solve this is to let dashing run on a path other than the default /. There is a bit of documentation for this approach in the Wiki.

这篇关于将路线添加到仪表板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆