简体   繁体   中英

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). 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.

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?

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. So if your app is displaying widgets, you could see them in the normal app behind the url /widgets. In order to edit them you would go to /admin/widgets (and also have to be logged in as an admin). Instead of just doing it via route namespaces, I also create an AdminController that all other controllers in that namespace extend. 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. You could also take a look at Streamlined or Hobo for this part as well.

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?

here is a link to the demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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