【问题标题】:Rails theming ONLY "new" posts in a blogRails 主题化只有博客中的“新”帖子
【发布时间】:2016-06-24 20:11:54
【问题描述】:

常见的解决方案侧重于为不同的页面或控制器创建主题或不同的 CSS 文件。

每当我创建新博客文章时,是否有解决方案,我也可以从下拉列表中选择一个主题,或者 new_post 页面中的 form_fields 会根据主题的选择更改样式、形状和布局,例如从侧边栏?

有没有类似的宝石,或者我们如何滚动相关的东西?

【问题讨论】:

  • 我不确定您的问题的范围,但是一个简单的 CSS 类可以改变帖子的整体外观,例如 <body class="themeA"> ,其中 "themeA" 存储在博客帖子中.您在寻找更复杂的东西吗?

标签: ruby-on-rails ruby ruby-on-rails-4 content-management-system themes


【解决方案1】:

在您的数据库中为“主题”添加一列,并为每个 Post 主题创建一个 CSS 文件。在您的视图中,使用存储在数据库中的值设置 Post 容器的 CSS。

theme-1.css

.theme-1 {
  /* Some CSS */
}

.theme-1 p {
  /* Some CSS */
}

...

theme-2.css

.theme-2 {
  /* Some CSS */
}

.theme-2 p {
  /* Some CSS */
}

...

posts/show.html.erb

<div '#post-container' class='<%= @post.theme %>' %>
  ...
</div>

posts/show.html

<div '#post-container' class='theme-1' %>
  ...
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    相关资源
    最近更新 更多