开发者

Restricting Access in ERB code

开发者 https://www.devze.com 2022-12-29 10:36 出处:网络
I am trying to build a CMS using ERB.Is there a way you can giv开发者_运维百科e ERB code read-only access to your models?For instance, I want to be able to load any information on my models (Model.all

I am trying to build a CMS using ERB. Is there a way you can giv开发者_运维百科e ERB code read-only access to your models? For instance, I want to be able to load any information on my models (Model.all, Model.find_by_slug, Model.find_by_name, Model.other_model.name, etc...), but I don't want to be able to change this data. Can you disable ERB from executing commands that would make database changes (Model.save, Model.update, Model.delete, Model.destroy, etc.)???


Give this a shot: http://www.liquidmarkup.org/


There is safemode by Rails core developer Sven Fuchs to make you erb, well, safer.

A template engine like liquid (which is painful in my eyes) or mustache might be easier to learn and apply for your users than erb.


Try to use :readonly flag while finding models:

@posts = Post.find(:all, :readonly => true)

In case you'll try to save it - will throw ReadOnlyRecord exception. But I'd also suggest Liquid as a templater, since user has no restricted access to application varibles inside ERB templates.

0

精彩评论

暂无评论...
验证码 换一张
取 消