Thursday, November 10, 2016

7 Design Patterns to Refactor MVC Components in Rails

dphead

In our previous post, The Basics of MVC in Rails, we discussed theoretical aspects of the MVC design pattern. We defined what MVC stands for, identified what each MVC component is responsible for, addressed what happens when a component contains redundant logic, and, most importantly, we introduced the concept of refactoring. In this article, as promised, we'll show you each design pattern at work.

Service Objects (and Interactor Objects)

Service Objects are created when an action:

  • is complex (such as calculating an employee's salary)
  • uses APIs of external services
  • clearly doesn't belong to one model (for example, deleting outdated data)
  • uses several models (for example, importing data from one file to several models)

Example

In the example below, work is performed by the external Stripe service. The Stripe service creates a Stripe customer based on an email address and a source (token), and ties any service payment to this account.

Continue reading %7 Design Patterns to Refactor MVC Components in Rails%


by Viktoria Kotsurenko via SitePoint

Nathan Rutzky

opl-small-nathco

Minimal personal One Pagers for UI designer, Nathan Rutzky. Basic but lovely font choice and a neat full page color load transition.

by Rob Hope via One Page Love

Boxus

Boxus

'Boxus' is unique, colorful One Page HTML template suited for a slick personal or digital agency portfolio. The design really is refreshing for a template with fancy scrolling sections and big typography. Features include image gallery, animated skills graph, preloader, contact form and Google Maps.

Great to know there is a WordPress version.

by Rob Hope via One Page Love

Bureau Cool

opl-small

Trippy One Pager for 'Bureau Cool' featuring a scrolling background of portfolio items with a spiralling logo overlay.

by Rob Hope via One Page Love

AtoZ CSS Screencast: The Z-index CSS Property

Some interface designs may call for elements to be layered or stacked on top of each other.

There are many ways that elements will naturally stack on top of each other. But we can control this stacking order using a combination of the position and z-index properties.

In this final episode of AtoZ CSS season one we’ll learn about:

  • The default stacking order of the document
  • What a stacking context is and how they interact with each other
  • How z-index controls layer order within stacking contexts
  • And a method I use for standardising z-index across a project

Default Stacking

When writing our HTML, elements that appear lower down in the document, naturally stack above elements further up.

[code language="html"]
<body>
<header class="site-header"></header>
<main class="site-content"></main>
<footer class="site-footer"></footer>
</body>
[/code]

Given this snippet of HTML, the footer would stack on top of the main content area which would stack on top of the header if they were all positioned to overlap each other.

Elements can be overlapped by using a combination of position properties and offset properties top, right, bottom and left.

If I set position:absolute on each of these elements, they will all layout on top of each other. The footer comes last in the document so by default stacks on top of the previous two elements.

Continue reading %AtoZ CSS Screencast: The Z-index CSS Property%


by Guy Routledge via SitePoint

Programming With Yii2: Using Ajax

Building Your Startup: Preparing for Reminders