Skip to content

Instantly share code, notes, and snippets.

module ParserModule
data = nil
pages = nil
def data=d
data = d
end
def data
data
module ParserModule
attr :pm_data, :pm_pages
def pages
if @pm_pages.nil?
@pm_pages = @pm_data.split /^\d{4}\s*$/
end
@pm_pages
end
<fieldset>
<legend><%= form_legend %></legend>
<div class='control-group<%= " error" if @user.errors.has_key?(:email) %>'>
<label class='control-label'>Email</label>
<div class='controls'>
<%= f.text_field :email, :class => 'input-xlarge' %>
<% if @user.errors.has_key?(:email) %>
<span class='help-inline'>Email <%= @user.errors.get(:email).first %></span>
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :first_name, :last_name, :organization, :email, :password, :password_confirmation, :remember_me, :is_admin, :plan
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"...",
"user"=>{"email"=>"[email protected]",
"password"=>"[FILTERED]",
"first_name"=>"Bob",
"last_name"=>"Jones",
"subscription"=>{"plan_id"=>"5"}},
"password_confirmation"=>"[FILTERED]",
"commit"=>"Update User",
ActiveRecord::RecordNotSaved in Admin::UsersController#update
Failed to remove the existing associated subscription. The record failed to save when after its foreign key was set to nil.
@PeteMichaud
PeteMichaud / draper_kaminari_patch.rb
Created July 19, 2013 17:08
Getting Draper and Kaminari to play nice together isn't straightforward. Add this file to the config/initializers/extensions/ path and it'll stop the errors about the DraperCollection not having various methods.
module Draper
class CollectionDecorator
delegate :current_page, :total_pages, :limit_value, :model_name, :total_count, :offset_value, :last_page?
end
end
@PeteMichaud
PeteMichaud / jekyll_import_converter.rb
Created September 7, 2013 17:23
After importing from Wordpress to Jekyll, you get your posts and pages in html format, without any hard line wraps. I wanted to get the files into markdown format and wrap the lines at 120 characters wide so I could edit it nicely in my IDE. I also have like 500 pages to convert, so doing it by hand was a nonstarter...
require 'html2markdown' #gem install html2markdown
dirs = %w(_pages _posts)
class String
def word_wrap(line_width = 120)
self.split("\n").collect do |line|
line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
end * "\n"
end
class Widget < ActiveRecord::Base
include Thingable
end
@PeteMichaud
PeteMichaud / gist:fd5ccea6f4d792188f459d3405d5e18d
Last active June 10, 2016 21:22 — forked from crova/'campaign_records'
iterates through each row but keep updating on the same db row
# fetchs SIB Campaigns
def fetch
# update/create
campaign_records.each do |record|
shoot = Shoot.find_or_initialize_by(campaign_id: record[:id])
unless shoot.update(record)
# the data was invalid, so the shoot wasn't saved, do something about that here
end
end