views:

59

answers:

3

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?

A: 

umm...i know herokugarden allows you to edit your code online through a browser, will that work?

here is a link to the demo

ez
A: 

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.

Andy Gaskell
I think it's a little more complex (but maybe not much more). I won't want to maintain two separate entries in config/database.yml, but it looks like I should be able to do something like<pre>tools: <<: *production</pre>I'm wondering if there are other touch-points to worry about when creating custom environments.That's a good point with the whitelisting, it's better than blacklisting.
etoleb
A: 

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.

Jeff Whitmire
I'd like to avoid implementing a user authentication system just to hide an admin toolset. It seems like an unnecessary security complication.With a tools mode I wouldn't necessarily need to run my admin jobs on the same machines that host my site. I don't want CPU intensive, long-running processes to impact live-site performance.Thanks for the advice on ActiveScaffold/Streamlined/Hobo, I suspect they'll be useful however I solve this problem.Good point about the "on the road", but it's not something I anticipate being a major factor (and it could be solved with a VPN later on).
etoleb