简体   繁体   English

在Rails应用程序中添加“工具模式”

[英]Adding a “tools mode” to rails app

Let's say I have a rails app with content that's read-only to the public, but I'd like to build tools to edit that content (or use scaffolding). 假设我有一个Rails应用,其内容是对公众只读的,但是我想构建工具来编辑该内容(或使用脚手架)。 I don't want to expose create/update/delete actions publicly (even if password-protected), but I'd like to have a server with this functionality inside a local network that interacts with the production database. 我不想公开地公开创建/更新/删除操作(即使受密码保护),但我想在与生产数据库交互的本地网络中安装一台具有此功能的服务器。

So I'm thinking of writing a plugin for this, which would add a tools rails environment (like development, production, and test) and a way of configuring a controller method as "tools-only". 因此,我正在考虑为此编写一个插件,这将添加一个工具导轨环境(如开发,生产和测试)以及一种将控制器方法配置为“仅工具”的方式。 When not in tools mode, requests for any tools-only action gets redirected to a standard 404 page. 当不在工具模式下时,对仅工具操作的请求将重定向到标准404页面。

Before I start reinventing a wheel, does something like this already exist? 在我重新发明轮子之前,是否已经存在类似的东西? Are there perhaps better ways to solve this problem? 是否有解决此问题的更好方法?

Interesting idea - Aside from creating the custom environment wouldn't it just be one before_filter in your Application controller? 有趣的想法-除了创建自定义环境以外,它还不是Application控制器中的一个before_filter吗?

before_filter :can_access_tools, :except => [:show, :index]

Other controllers would just skip it as need be. 其他控制器会根据需要跳过它。

Why do it as a separate environment? 为什么将其作为独立的环境? What I would do (and have done) is put the editing functionality in a separate namespace (I usually call it admin), then using a before filter only allow a user with an admin role access to those controllers. 我要做的(和已经做的)是将编辑功能放在一个单独的命名空间中(我通常将其称为admin),然后使用before过滤器仅允许具有admin角色的用户访问这些控制器。 So if your app is displaying widgets, you could see them in the normal app behind the url /widgets. 因此,如果您的应用程序显示小部件,则可以在url / widgets后面的普通应用程序中看到它们。 In order to edit them you would go to /admin/widgets (and also have to be logged in as an admin). 为了编辑它们,您将转到/ admin / widgets(并且还必须以admin身份登录)。 Instead of just doing it via route namespaces, I also create an AdminController that all other controllers in that namespace extend. 我不仅创建了路由名称空间,还创建了一个AdminController,该名称空间中的所有其他控制器都进行了扩展。 Then you can put any filters that need to apply to all of them in one place. 然后,您可以将需要应用于所有过滤器的所有过滤器放在一个位置。

You could get the UI for this up pretty quick by dropping in something like Active Scaffold to provide a pretty clean interface to do CRUD operations on it. 您可以通过放入Active Scaffold之类的东西来提供一个非常干净的界面来对其执行CRUD操作,从而很快获得用于此目的的UI。 You could also take a look at Streamlined or Hobo for this part as well. 您也可以在此部分中查看StreamlinedHobo

I often set up extra environments for testing multiple contexts, but for this case it seems like overkill. 我经常设置额外的环境来测试多个上下文,但是在这种情况下,这似乎有些过头了。 If you limit the editing functionality by authorization (requiring the role of admin) instead of by access (only the local server can get to it), it also allows you to make changes if you're on the road and not in the office. 如果您通过授权(要求管理员的角色)而不是通过访问权限(仅本地服务器可以访问)来限制编辑功能,则它还允许您在旅途中而不是在办公室中进行更改。

umm...i know herokugarden allows you to edit your code online through a browser, will that work? 嗯...我知道herokugarden允许您通过浏览器在线编辑代码,这样行得通吗?

here is a link to the demo 这是演示的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM