Skip to content

Instantly share code, notes, and snippets.

View xander-miller's full-sized avatar

Xander Miller xander-miller

View GitHub Profile
target_beer = Beer.find_by_name(beer_name)
posts_with_beer = Post.all.keep_if{|post| post.beers.include?{target_beer}}
<div class="row">
<div class="span8">
<h1><%= @post.title %></h1>
<small>
submitted <%= time_ago_in_words(@post.created_at) %> ago by
<%= @post.user.name %>
</small>
<p><%= @post.body %></p>
</div>
<div class="col-md-4">
require 'faker'
#create 15 topics
topics = [ ]
15.times do
topics << Topic.create(
name: Faker::Lorem.sentence,
description: Faker::Lorem.paragraph)
end
@xander-miller
xander-miller / hashes.rb
Last active August 29, 2015 13:59
Bloc Exercises with Comments
def hash_to_array(h = {})
key_value_array = []
h.each do |key, value|
key_value_array << "#{key} is #{value}"
end
key_value_array
end
#!/usr/bin/env ruby
require_relative '../lib/house'
srand(17)
SUBJECTS = [
'the horse and the hound and the horn that belonged to',
'the farmer sowing his corn that kept',
'the rooster that crowed in the morn that woke',
'the priest all shaven and shorn that married',
@xander-miller
xander-miller / robert.js
Created April 27, 2014 20:08
Bedroom stuff
var url = ""; //Set the url to an empty string
if($(".cb1BR")[0].checked) { //Add a little extra to the string if a box is checked
url = url + "bedrooms[]=1&"
}
if($(".cb2BR")[0].checked) {
url = url + "bedrooms[]=2&"
}
require 'faker'
# Create Users
5.times do
user = User.new(
name: Faker::Name.name,
email: Faker::Internet.email,
password: Faker::Lorem.characters(10)
)
user.skip_confirmation!
class WikisController < ApplicationController
before_action :set_wiki, only: [:show, :edit, :update, :destroy]
# GET /wikis
# GET /wikis.json
def index
@wikis = policy_scope(Wiki)
end
class WikiPolicy < ApplicationPolicy
class Scope < Struct.new(:user, :scope)
def resolve
if user.admin?
scope.all
else
scope.where(user: user)
end
end
<h1>My wikis</h1>
<div class="row">
<% if policy(Wiki.new).create? %> <%#added policy instead of if user %>
<%= link_to 'New', new_wiki_path, class: 'btn btn-primary btn-large' %>
<% end %>
<% if current_user.role?("free") %>
<h2><%= link_to "Upgrade Account", new_charge_path, class: 'btn btn-primary btn-large' %></h2>
</div>
<% end %>