Skip to content

Instantly share code, notes, and snippets.

@tpett
Last active May 3, 2018 17:59
Show Gist options
  • Save tpett/6c25f8664032b605f93dce7a35f64486 to your computer and use it in GitHub Desktop.
Save tpett/6c25f8664032b605f93dce7a35f64486 to your computer and use it in GitHub Desktop.
Rapid UI Prototyping in Rails

This is a first pass at a rapid UI prototyping pattern within a Rails app. A few notes

  1. Create any partials you want to match to URLs in app/views/prototype
  2. Crosslink between the different partials with <a href="/widgets-list">Widgets</a> or link_to.
  3. You have access to Ruby code for generating random data or even DB calls if needed.
  4. You can also use params for tweaking title text or other minor details in each page.
<%= render @prototype %>
class PrototypeController < ApplicationController
def show
url_parts = params[:url].split('/').select(&:present?)
@prototype = url_parts.join('/')
# Trigger 404 if there's no partial for this URL
unless lookup_context.exists?(@prototype, 'prototype', true)
raise ActionController::RoutingError.new('Not Found')
end
end
end
Rails.application.routes.draw do
# Other App routes
# Catch unmatched routes and send them to the PrototypeController#show
get '/*url' => 'prototype#show'
root to: 'prototype#show', url: '/accounts'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment