This file contains hidden or 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 hidden or 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
<%= 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> |
This file contains hidden or 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 hidden or 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 %> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 =[] | |
60.times do | |
topic = Topic.create( | |
name: Faker::Lorem.sentence, | |
description: Faker::Lorem.paragraph | |
) | |
topic.save |
NewerOlder