advertisement

Building and Working With Static Sites in Ruby on Rails

39 %
61 %
advertisement
Information about Building and Working With Static Sites in Ruby on Rails

Published on July 18, 2007

Author: viget

Source: slideshare.net

Description

Ben Scofield presents his solution for building web applications in Rails that contain a large chunk of static content. This approach merges the management of static content with the power that the Rails framework provides to developers.
advertisement

Building and Working with Static Sites in Ruby on Rails Ben Scofield ben@viget.com Senior Developer, Viget Labs May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

2 Me • 8 years building web apps (Perl, VBScript, C#, Java, PHP) • Ruby and Rails for 2 years • Tech Lead for Seth Godin’s Squidoo • ben@viget.com Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

3 Viget Labs • Full-service web design and development consultancy • Three types of clients – Flash-based entertainment sites – Web 2.0 startups – Mid-sized, mostly static sites Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

4 “Static” sites • Fully static: CMS • Small scale: About Us, Contact Info • Large scale: ACVA (funside.com) Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

5 Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

6 Hybrid sites • Distinct static and dynamic content (About Us) • Intermingled static and dynamic content Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

7 THE PROBLEM • Building a static site should be easy Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

8 And in PHP, it is • Drop a file and see it run, even with embedded PHP code • Use configuration files to route requests, set page-specific data, handle redirects, set page metadata... Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

9 But in Rails? • Actions for every view? sigh • Actionless views? pfft • and what about page-specific data? Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

10 So why bother with Rails? • Less interesting: morale • More interesting: productivity – task switching and specialization • Most interesting: hybrid sites – current and future Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

11 Notes • Error handling - ignore its absence • Historical tour, Edge at the time Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

12 Solution 1: Rails on PHP • Routing + Convention + Action + Caching = basic PHP? Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

13 Routing • The beauty of the catch-all route: • Declare all other routes explicitly! or namespace the catch-all: Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

14 Convention • All templates under a single app/views subfolder • Move as much to the layout as possible Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

15 Action Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

16 Caching • Short and sweet: caches_page :show • Rails caches under the request URI, not the controlller/action Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

17 Problems with Solution #1 • Manage page data in the views? pfft • Manually expire the cache? pfft • No support for redirects (site revisions)? pfft Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

18 Solution 2: Configuratron 2000 • Use configuration files to overcome the problems of Solution 1 Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

19 navigation.yml • Central management for pages, page data, and relationships Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

20 Memory’s cheap, right? • Load it all into memory • and pull it out when you need it Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

21 Caching • Expire the entire cache when navigation.yml is updated Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

22 redirects.yml • Use the redirect entry to find the new page Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

23 Problems with Solution #2 • Keeping it all in memory? pfft • Upload new config files to change content? pfft • All-or-nothing caching? pfft • Not very Rails Wayish, is it? Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

24 Solution 3: CRUDification • So what is Rails best at? – CRUD! • Can we make static sites CRUDdier without creating a full-blown CMS? Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

25 Move it all to the DB... Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

26 Pages and Variables Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

27 Redirects Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

28 Sitemaps for nothing Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

29 Cascading Variables for Free Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

30 Web UI Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

31 Cache sweeping made easy Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

32 Problems with Solution #3 • Search • Portability Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

33 Solution 4: Feed the DB • Store page content in the DB • Upload files or enter content through the UI • Search with ... whatever Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

34 Reduce, Reuse, Recycle • Package the framework for distribution Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

35 Question 1: To Engine or To Plugin? • Engines – Cons: deprecated, people yell at you • Plugins – Pros: everybody loves plugins! Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

36 Question 2: To Generate or To App? • Generators – Pros: customized code – Cons: hard to update • Plugin Applications – Pros: easy to update, fast start – Cons: possible conflicts Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

37 Plugin Applications • Miniature Rails applications - controllers, models, and views • Grant complete, self-contained functionality to another application Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

38 Using the framework • Install the plugin-app • Update config files – environment.rb and routes.rb – (optional) .htaccess and environment.rb • Run the migrations • Enjoy your newly more-static site! Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

39 Key Points • The catch-all route is the best kind of magic • Play to Rails’ strengths • Handle both large- and small-scale static sites Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

40 Get the (alpha) framework at http://www.viget.com/railsconf/ Questions? Ask ‘em now or email me at ben@viget.com Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

41 No questions, eh? • Why even bother with this? Why not a CMS? • Use content_for in the views to move more to the layout • Plugems vs. engines vs. plugins? • More about plugin-apps? Viget Labs we build web business May 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com

Add a comment

Related pages

Building and Working with Static Sites in Ruby on Rails

Session Building and Working with Static Sites in Ruby on Rails. Ben Scofield, Senior Developer, Viget Labs Date: Friday, May 18 Time: 1:50pm - 2:40pm
Read more

How: Ruby on Rails to build a basic site - Stack Overflow

... Ruby on Rails to build a basic site ... Since your site looks to be all static pages except for the ... Building a ruby gem for Rails ...
Read more

Rails Routing from the Outside In — Ruby on Rails Guides

Rails Routing from the Outside In. ... 3.3 Static Segments. ... any kind of discussion regarding Ruby on Rails documentation is very welcome in the ...
Read more

Ruby on Rails

Ruby on Rails is open source software, so not only is it free to use, you can also help make it better. More than 4,200 people already have contributed ...
Read more

Building static websites with Middleman | 12 Devs is back!

... that utilises some of the power of Rails (the popular Ruby ... Building static ... http://codecondo.com/7-static-site-generators-for-building ...
Read more

Getting Started with Rails — Ruby on Rails Guides

Getting Started with Rails. This guide covers getting up and running with Ruby on Rails. ... Before you can start building the application ...
Read more

Build a Simple Ruby on Rails Application Course

Ruby on Rails is a web application framework which makes it easy and quick to build dynamic web sites. ... Ruby on Rails is ... Build a Simple Ruby on ...
Read more

ActionView::Helpers::FormHelper - Ruby on Rails API

Module ActionView::Helpers::FormHelper ... Form helpers are designed to make working with resources much easier compared to ... In Rails, this is usually ...
Read more

Rails Girls App Tutorial - Rails Girls

... then click Command Prompt with Ruby on Rails. ... Lets add a static page to our app that will hold information about the author of this application ...
Read more