Skip to content

Instantly share code, notes, and snippets.

%ul
= @listings.inspect
- @listings.each do |l|
%li
= l
%span= link_to "Delete This Batch", boss_listing_path(l), :method => :delete, :confirm => "Are you SURE you want to delete all listings with this identifier? This cannot be undone."
def destroy
@listings = Listing.where(:listing_name => params[:listing_name])
@listings.destroy
redirect_to organizations_url, :notice => "Successfully destroyed this group of listings."
end
class Ability
include CanCan::Ability
def initialize user, options = {}
user ||= User.new
role_call = ["admin", "boss", "exporter", "member"]
role_call.each do |r|
if user.roles.has?(r)
"#{r}" + _rules
else
@jonpaul
jonpaul / ability.rb
Created November 15, 2011 19:47
uninitialized user?
class Ability
include CanCan::Ability
def initialize(user, options = {})
user ? user_rules : guest_rules
end
def user_rules
user.roles.each { |role| exec_role_rules(role) if user.roles.include? role }
default_roles
@jonpaul
jonpaul / new.html.erb
Created November 9, 2011 21:00
Devise nested form issue
<h2>Sign up</h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<% f.object.build_organization unless f.object.organization %>
<% f.fields_for :organization do |o| %>
<p><%= o.label :name %><br/>
<%= o.text_field :name %></p>
class AddDeviseToUsers < ActiveRecord::Migration
def self.up
change_table :users do |t|
t.recoverable
t.rememberable
t.trackable
t.validatable
t.lockable
t.timeoutable
end
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 26364/mongod
tcp 0 0 0.0.0.0:28017 0.0.0.0:* LISTEN 26364/mongod
tcp 0 0 50.57.132.151:27017 50.57.132.151:44988 ESTABLISHED 26364/mongod
unix 2 [ ACC ] STREAM LISTENING 2929563 26364/mongod /tmp/mongodb-27017.sock
@jonpaul
jonpaul / ruby_modes.rb
Created November 3, 2011 21:03
Ruby mode's for IO class
Mode | Meaning
-----+--------------------------------------------------------
"r" | Read-only, starts at beginning of file (default mode).
-----+--------------------------------------------------------
"r+" | Read-write, starts at beginning of file.
-----+--------------------------------------------------------
"w" | Write-only, truncates existing file
| to zero length or creates a new file for writing.
-----+--------------------------------------------------------
"w+" | Read-write, truncates existing file to zero length
@jonpaul
jonpaul / blurb.rb
Created November 2, 2011 19:55
pages, contents, blurbs
class Blurb < ActiveRecord::Base
default_scope :order => 'weight ASC'
has_many :contents,
:foreign_key => "blurb_id",
:dependent => :destroy
has_many :pages, :through => :contents
end
c3583c6 HEAD@{0}: checkout: moving from master to c3583c6
2635ee1 HEAD@{1}: commit: I may have broken something, checking...