Rails beginner
Rails beginner

Reputation: 14514

Rails how to edit and save files in browser?

I want to make a CMS where I can edit the view and css files online in my browser. How can it be done? Does everything have to be in a database?

Upvotes: 2

Views: 817

Answers (1)

coreyward
coreyward

Reputation: 80090

Generally Stack Overflow is not for research, it's for problem solving. That said…

  1. No, your editable assets do not have to be in a database for this to work.
  2. But you want them to be anyways; allowing write access to the files in your application isn't the best approach.
  3. The rendering chain of Rails 3 allows you to sub in your own view parser and add a path to the built in view-finding that you can trick into loading from a database relatively easily.
  4. Having your end users write in something like Liquid templates will save you a lot of work and allow this to happen with relative ease. They won't have access to unsafe Ruby methods, and you won't have to go through all the work of sandboxing them in Ruby.
  5. CSS has fewer security implications, so you can fairly easily store raw CSS in the database and allow your users to edit it to their liking and then serve it up with a request to a stylesheets/:user_id/style.css request (with some heavy caching, like with Varnish, to save your application from being murdered).

Hopefully that'll get you started out in the right direction. If you decide to hook into the rendering stack in Rails I strongly suggest you pickup a copy of Crafting Rails Applications — one of the handful of example applications it walks you through does just that at a fairly granular level.

Upvotes: 3

Related Questions