`
hideto
  • 浏览: 2678109 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

每天一剂Rails良药之Cheap and Easy Theme Support

    博客分类:
  • Ruby
阅读更多
你可能需要给你的站点用户添加一个主题样式支持。
让我们看看用Rails实现该功能是多简单。

1,给User模型添加类型为string的style字段

2,修改app/views/layouts/application.rhtml
<html>
    <head>
        <%= stylesheet_link_tag(session[:user].style || "default") %>
    </head>
    <body>
        <div id='main'>
            <div id='header'>
                <h1>Welcome, <%= session[:user].name %>!</h1>
            </div>
            <div id='content'>
                <%= yield %>
            </div>
        </div>
    </body>
</html>

这样没有配置主题样式的用户将默认使用default.css,而User.style为"hideous"的用户将使用public/stylesheets/hideous.css
分享到:
评论

相关推荐

    Rails.Angular.Postgres.and.Bootstrap.2nd.Edition

    When used together, these powerful and easy-to-use tools will open you to a new world of possibilities. This second edition is updated to cover Angular 2 - a completely reworked front-end framework -...

    Ruby on Rails_ Up and Running

    RUBY的经典之作,对其在RAILS下开发写得很详细

    Rails Solutions Ruby on Rails Made Easy

    《Rails解决方案:Ruby on Rails变得轻松》一书由Justin Williams编写,旨在为读者提供一种无需深厚编程背景即可创建动态Web应用程序的方法。本书聚焦于Ruby on Rails框架,这是一套流行的Web开发工具,以其高效、...

    Rails Recipes (2006) .pdf

    Cheap & Easy Theme Support**:提供了一种简单且成本低廉的方式,用于支持网站的主题切换。 - **9. Trim Static Pages with Ajax**:讲解了如何利用 AJAX 技术减少静态页面的加载时间。 - **10. Smart ...

    Rails 101 入门电子书

    《Rails 101 入门电子书》是一本非常适合初学者直接入门的书籍,它由xdite编写并出版于2014年6月10日。本书主要针对的是希望学习Ruby on Rails框架的读者,特别是那些想要从零开始掌握这项技术的新手。 #### 二、...

    Rails Recipes Final.pdf

    **Cheap & Easy Theme Support**:低成本且简单的主题支持方案,使开发者能够轻松地为应用添加多套样式主题。 9. **Trim Static Pages with Ajax**:使用Ajax技术精简静态页面,提高页面加载速度和用户体验。 10....

    关于rails 3.1 cucumber-rails 1.2.0

    Rails 3.1 和 Cucumber-Rails 1.2.0 是两个在Web开发领域非常重要的工具,尤其对于Ruby on Rails框架的测试和自动化流程。本文将深入探讨这两个组件,以及它们如何协同工作来增强软件开发的效率和质量。 首先,...

    NetBeans Ruby and Rails IDE with JRuby 2009

    总结来说,《NetBeans Ruby and Rails IDE with JRuby 2009》是一本详尽介绍了如何使用NetBeans作为Ruby和Rails开发工具的指南。它不仅覆盖了从安装到日常开发的所有方面,还深入探讨了如何利用NetBeans的各种高级...

    rails2-sample

    从给定的文件信息来看,我们正在探讨的是一本关于Ruby on Rails的书籍,书名为《Simply Rails2》,作者是Patrick Lenz。本书旨在为初学者提供深入理解Ruby on Rails框架的指南,从基础概念到高级主题均有涵盖,是...

    Rails, Angular, Postgres, and Bootstrap(Pragmatic,2016)

    As a Rails developer, you care about user experience and performance, but you also want simple and maintainable code. Achieve all that by embracing the full stack of web development, from styling with...

    [Rails] Crafting Rails 4 Applications (英文版)

    Eight different test-driven tutorials will help you understand Rails' inner workings and prepare you to tackle complicated projects with solutions that are well-tested, modular, and easy to maintain....

    Rails3 device and cancan

    标题《Rails3 device and cancan》与描述《ROR ruby on rails device plugin教程》指出本文是关于如何在Rails 3.2应用程序中整合Devise认证插件和Cancan授权插件的教程。Devise是一个流行的Ruby on Rails的认证解决...

    Rails101_by_rails4.0

    《Rails101_by_rails4.0》是一本专注于Rails 4.0.0版本和Ruby 2.0.0版本的自学教程书籍,它定位于中文读者,旨在成为学习Rails框架的参考教材。Rails(Ruby on Rails)是一个采用Ruby语言编写的开源Web应用框架,它...

    [Rails] Crafting Rails Applications (英文版)

    This pioneering book is the first resource that deep dives into the new Rails 3 APIs and shows you how use them to write better web applications and make your day-to-day work with Rails more ...

    Agile Web Development with Rails 4

    You concentrate on creating the application, and Rails takes care of the details., Tens of thousands of developers have used this award-winning book to learn Rails. It’s a broad, far-reaching ...

    Beginning Ruby on Rails

    Ruby on Rails is the revolutionary online programming tool that makes creating functional e-commerce web sites faster and easier than ever. With the intuitive, straightforward nature of Ruby and the ...

    Agile Web Development with Rails Final

    - Rails is designed to support agile methodologies, allowing teams to iterate quickly, deliver value early, and adapt to changing requirements. Its flexible structure enables developers to implement ...

Global site tag (gtag.js) - Google Analytics