Skip to content

Instantly share code, notes, and snippets.

@tochman
tochman / spec_helper.rb
Last active January 17, 2018 17:01
Rspec settings for use with Middleman (acceptance tests)
require 'rspec'
require 'capybara/rspec'
require 'middleman-core'
require 'middleman-core/rack'
require 'middleman-livereload'
require 'middleman-deploy'
require 'middleman-sprockets'
middleman_app = ::Middleman::Application.new
@nbhartiya
nbhartiya / your_controller.rb
Created February 19, 2015 22:13
Javascript Embeddable Widget: Working with CORS
class YourController < ApplicationController
before_filter :cors_preflight_check, only: [:settings]
after_filter :cors_set_access_control_headers, only: [:settings]
def settings
# YOUR CODE TO GET CLIENT'S WIDGET SETTINGS HERE
end
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
@Joseph-N
Joseph-N / _message.html.erb
Last active April 15, 2021 11:09
Tutorial code snippets for chat application in rails. Tutorial link http://goo.gl/l3e8zN
<li class="<%= self_or_other(message) %>">
<div class="avatar">
<img src="http://placehold.it/50x50" />
</div>
<div class="chatboxmessagecontent">
<p><%= message.body %></p>
<time datetime="<%= message.created_at %>" title="<%= message.created_at.strftime("%d %b %Y at %I:%M%p") %>">
<%= message_interlocutor(message).name %><%= message.created_at.strftime("%H:%M %p") %>
</time>
</div>
@minipai
minipai / gist:3150020
Created July 20, 2012 10:18
Middleman 3 Template Layouts
title
Layouts &amp; Partials

Layouts

Layouts allow the common HTML surrounding individual pages to be shared across all your templates. The most basic layout has some shared content and a yield call where templates will place their contents. Furthermore, With wrap_layout, content_for and partial you can build a complex layout inheritance, reduce the duplication of you code in templates to a minimal amount.

Basic layout

@daz
daz / edit.html.erb
Created February 22, 2012 09:13
twitter-bootstrap-rails ERB template
<%= render :partial => 'form' %>
@thomasyip
thomasyip / config.ru
Created October 26, 2011 05:46
Config.ru for Rails meets Sinatra
# /config.ru
# This file is used by Rack-based servers to start the application.
# For Rails
require ::File.expand_path('../config/environment', __FILE__)
# For Sinatra
require './slim/slim.rb'
# - Make sinatra play nice
use Rack::MethodOverride
@woods
woods / tinyurl.rb
Created April 11, 2009 15:43
A complete URL-shortening web application, written in Ruby/Sinatra.
#!/usr/bin/env ruby
#
# A complete URL-shortening web application, written in Ruby/Sinatra. Run it
# from the command line, and then visit http://localhost:4567/
#
# Or to run it under apache/passenger, you'll need a config.ru file with the
# following contents:
#
# require 'tinyurl'
# run Sinatra::Application