Skip to content

Instantly share code, notes, and snippets.

Avatar

Xander Miller xander-miller

View GitHub Profile
View noe_seed.rb
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!
View wiki_policy.rb
class WikiPolicy < ApplicationPolicy
class Scope < Struct.new(:user, :scope)
def resolve
if user.admin?
scope.all
else
scope.where(user: user)
end
end
View doug_form.html.erb
<%= form_for(@wiki) do |f| %>
<% if @wiki.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@wiki.errors.count, "error") %> prohibited this wiki from being saved:</h2>
<ul>
<% @wiki.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
View wikis_controller.rb
class WikisController < ApplicationController
before_action :set_wiki, only: [:show, :edit, :update, :destroy]
# GET /wikis
# GET /wikis.json
def index
@wikis = policy_scope(Wiki)
end
View wikis_controller.rb
class WikisController < ApplicationController
before_action :set_wiki, only: [:show, :edit, :update, :destroy]
# GET /wikis
# GET /wikis.json
def index
@wikis = policy_scope(Wiki)
end
View wikis.index.html.erb
<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 %>
View jr_seed.rb
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!
View keaton_seeds.rb
require 'faker'
#create 15 topics
topics = [ ]
15.times do
topics << Topic.create(
name: Faker::Lorem.sentence,
description: Faker::Lorem.paragraph)
end
View viv_posts_show.html.erb
<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">
View marcus_seeds.rb
require 'faker'
# Create 15 topics
topics =[]
60.times do
topic = Topic.create(
name: Faker::Lorem.sentence,
description: Faker::Lorem.paragraph
)
topic.save