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
| def sort_by_length(sort_this_array) | |
| sort_this_array.sort {|x,y| x.length <=> y.length} | |
| end | |
| def filter(filter_this_array) | |
| filter_this_array.select {|num| num > 5} | |
| end | |
| filter([1, 3, 7, 8]) |
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 Shape | |
| attr_accessor :color | |
| def initialize(color = nil) | |
| @color = color || 'Red' | |
| end | |
| def larger_than?(other) | |
| self.area > other.area | |
| 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 User < ActiveRecord::Base | |
| # Include default devise modules. Others available are: | |
| # :confirmable, :lockable, :timeoutable and :omniauthable | |
| devise :database_authenticatable, :registerable, | |
| :recoverable, :rememberable, :trackable, :validatable, :confirmable | |
| # Setup accessible (or protected) attributes for your model | |
| attr_accessible :email, :password, :password_confirmation, :remember_me, :name, | |
| has_many :posts |
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>Welcome to Freshitoff</h1> | |
| <p>A simple application for createing To-Do lists.</p> | |
| <div class="btn-group-vertical"> | |
| <% @todos.each do |todo| %> | |
| <button type="button" class="btn btn-default"><%= todo.description %></button> | |
| <% end %> | |
| </div> | |
| <ul class="nav nav-pills"> |
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 < Struct.new(:user, :wiki) | |
| def update? | |
| if user.role?(:admin) | |
| scope.all | |
| elsif user.role?(:premium) | |
| wiki.user == user || wiki.collaborators.map{|collab| collab.user}.include?(user) || !wiki.private? | |
| else | |
| scope.where(:private => false) | |
| 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
| 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
| <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 |