This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
target_beer = Beer.find_by_name(beer_name) | |
posts_with_beer = Post.all.keep_if{|post| post.beers.include?{target_beer}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'faker' | |
#create 15 topics | |
topics = [ ] | |
15.times do | |
topics << Topic.create( | |
name: Faker::Lorem.sentence, | |
description: Faker::Lorem.paragraph) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hash_to_array(h = {}) | |
key_value_array = [] | |
h.each do |key, value| | |
key_value_array << "#{key} is #{value}" | |
end | |
key_value_array | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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&" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WikisController < ApplicationController | |
before_action :set_wiki, only: [:show, :edit, :update, :destroy] | |
# GET /wikis | |
# GET /wikis.json | |
def index | |
@wikis = policy_scope(Wiki) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WikiPolicy < ApplicationPolicy | |
class Scope < Struct.new(:user, :scope) | |
def resolve | |
if user.admin? | |
scope.all | |
else | |
scope.where(user: user) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 %> |