0

in my Rails application, a user can refer to a "sample" list of policies and create their own policies based on these samples. I am currently storing the list of "sample" policies and their associated textual HTML descriptions in a SamplePolicy model with a column name Content. Users can read about these sample policies and then create their own versions which are in turn stored in another model called Policy which holds a one-to-many relation with SamplePolicy model. See database structure below:

SamplePolicy
--------------------------------------------------------------
|  ID  |  Name                |  Content | 
--------------------------------------------------------------
|   1  |    Privacy           | <html>Sample..</html>
--------------------------------------------------------------
|   2  |    Copyright policy  |  <html> Sample....</html>
--------------------------------------------------------------

Policy
---------------------------------------------------------------------------------------
|  ID  |  Name                       |        Content               | samplepolicy_id
---------------------------------------------------------------------------------------
|   1  |   Custom Privacy            | <html>My Sample..</html>     |   1
--------------------------------------------------------------------------------------
|   2  |   Custom Copyright policy  |  <html> My Sample....</html> |   2
--------------------------------------------------------------------------------------

Question is:

Is this the best way to structure my models? Since the list of "Sample policies" does not change, I guess I can use "seeds.rb" to populate my application but then I will not be able to refer to these sample policies in my Policy model (See foreign key samplepolicy_id). But then again, I am not sure about storing HTML content in my database.

4

1 回答 1

0

如果您有多个示例策略,我认为单独的模型既干净又简单。存储 HTML 很好。您可以使用纺织品,以便用户可以更轻松地将样本复制和编辑到他们自己的策略中。

如果您确实存储 HTML,则只需在渲染时使用 html_safe。

于 2012-10-09T11:13:39.077 回答