Skip to content

Instantly share code, notes, and snippets.

View tubbo's full-sized avatar
:shipit:
i don't make rails apps you use, i make the rails apps you use faster..

Tom Scott tubbo

:shipit:
i don't make rails apps you use, i make the rails apps you use faster..
View GitHub Profile
<%= form_for @project do |f| %>
<% if @project.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@project.errors.count, "error") %> prohibited
this project from being saved:</h2>
<ul>
<% @project.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
def insert_flash
content_tag :div, class: 'flash' do
flash.each do |name, msg|
if msg.is_a?(String)
concat( content_tag( :div, class: "fade in alert alert-#{ flash_type_to_bootstrap(name) }") do
concat( button_tag( "&times;".html_safe, class: "close", "aria-hidden" => true, "data-dismiss" => "alert" ) )
concat( content_tag :div, msg, :id => "flash_#{name}" )
end )
end
end
_team_special.html.erb
_team_normal.html.erb
_team_keith.html.erb
@tubbo
tubbo / gist:8221335
Last active January 2, 2016 00:09 — forked from anonymous/gist:8221276
%body
-if controller_name == 'home'
:javascript
$(document).on('ready page:load', function() {
Shadowbox.init();
});
def create_migration(table_name, columns="")
utc_now = Time.now.getutc.strftime("%Y%m%d%H%M%S")
class_name = table.classify.pluralize
file "db/migrate/#{utc_now}_create_#{table}.rb", %{
class Create#{class_name} < ActiveRecord::Migration
def change
create_table(:#{table_name}) do |t|
#{columns}
t.timestamps
end
Failures:
1) PostsController POST create with valid params creates a new Post
Failure/Error: expect {
count should have been changed by 1, but was changed by 0
# ./spec/controllers/posts_controller_spec.rb:47:in `block (4 levels) in <top (required)>'
2) PostsController POST create with valid params assigns a newly created post as @post
Failure/Error: assigns(:post).should be_persisted
expected persisted? to return true, got false
@tubbo
tubbo / searchable.rb
Last active December 28, 2015 19:29 — forked from anonymous/gist:7550493
def get_filters
searchable_named_columns.reduce({}) do |hash, col|
hash[col.send(:name) || col['name']] = col
end
end
def searchable_named_columns
searchable_columns.select { |col| col.respond_to? :name }
end
module ElasticSearch
module RefreshIndex
extend ActiveSupport::Concern
included do
after_save :refresh_index
after_destroy :refresh_index
end
def refresh_index
<h4><%= comment.author %></h4>
<%= form_tag url_path, method: "get", id: "search", class: "form-inline", role: "form" do %>
<%= end %>
<%= render 'bulk_action_form' %>