Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ class ApplicationController < ActionController::Base
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name])
end

def authenticate_admin!
unless user_signed_in? && current_user.admin?
redirect_to root_path, notice: "We're sorry, this resource is reserved" +
" exclusively for site admins."
end
end
end
36 changes: 36 additions & 0 deletions app/controllers/demos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class DemosController < ApplicationController
before_action :authenticate_admin!

def new
@demo = Demo.new
end

def create
@demo = Demo.new(demo_params)

if @demo.save
redirect_to root_path
flash[:notice] = "Video has been uploaded"
else
flash[:notice] = @demo.errors.full_messages
render :new
end
end

def show
@demos = Demo.all
if !@demos.empty?
@demo = Demo.where(name: "site demo")
end
end

def edit
@demo = Demo.find(params[:id])
end

private

def demo_params
params.require(:demo).permit(:name, :video, :description)
end
end
5 changes: 5 additions & 0 deletions app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ def index
if user_signed_in?
@user = current_user
@recipes = @user.recipes.sample(5)
else
@demos = Demo.all
if !@demos.empty?
@demo = Demo.where(name: "site demo")
end
end
end

Expand Down
5 changes: 5 additions & 0 deletions app/models/demo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Demo < ApplicationRecord
validates :name, presence: true
validates :description, presence: false
validates :video, presence: true
end
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ def profile
Profile.where(user: User.ids)
end

def admin?
role == "admin"
end

has_many :recipes
end
1 change: 1 addition & 0 deletions app/views/demos/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<% render 'new', demo: @demo %>
38 changes: 38 additions & 0 deletions app/views/demos/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<%= form_for @demo do |f| %>

<div class="error-messages">
<% if @demo.errors.any? %>
<p><%= pluralize(@demo.errors.count, "error(s)") %> prohibited this demo from being saved:</p>
<ul>
<% @demo.errors.full_messages.each do |m| %>
<li><%= m %></li>
<% end %>
</ul>
<% end %>
</div>

<div class="row">
<div class="large-11 small-11 large-11 columns">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div><br><br>

<div class="row">
<div class="video-input">
<%= f.label :video %><br>
<%= f.text_field :video %>
</div><br><br>
</div>

<div class="row">
<div class="large-11 small-11 large-11 columns">
<%= f.label :description %><br>
<%= f.text_area :description %>
</div><br><br>
</div>
</div>

<div class="save">
<%= f.submit '+'%><br><br>
</div>
<% end %>
5 changes: 5 additions & 0 deletions app/views/demos/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% if !@demos.empty? %>
<p><% @demo.video %></p>
<%= link_to 'Edit Site Demo', edit_demo_path(@demo) %> |
<p><% @demo.description %></p>
<% end %>
3 changes: 3 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<% end %>
<%= link_to 'Your Recipes', user_recipes_path(current_user)%> |
<%= link_to 'Add Recipe', new_user_recipe_path(current_user)%> |
<% if current_user && current_user.admin? %>
<%= link_to 'Add Site Demo', new_demo_path %> |
<% end %>
<div class="dropdown">
<a class="dropbtn"><i class="fa fa-cogs"></i></a>
<div class="dropdown-content">
Expand Down
6 changes: 6 additions & 0 deletions app/views/welcome/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
</div>
<% end %>
</ul>
<% else %>
<% if !@demos.empty? %>
<p><% @demo.video %></p>
<%= link_to 'Edit Site Demo', edit_demo_path(@demo) %> |
<p><% @demo.description %></p>
<% end %>
<% end %>
</div>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

resources :instructions
resources :ingredients
resources :demos

root 'welcome#index'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20170421130857_create_demos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateDemos < ActiveRecord::Migration[5.0]
def change
create_table :demos do |t|
t.string :video
t.string :description
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20170421131516_add_name_to_demos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNameToDemos < ActiveRecord::Migration[5.0]
def change
add_column :demos, :name, :string
end
end
5 changes: 5 additions & 0 deletions db/migrate/20170421141345_add_role_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddRoleToUsers < ActiveRecord::Migration[5.0]
def change
add_column :users, :role, :string
end
end
9 changes: 8 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170330001559) do
ActiveRecord::Schema.define(version: 20170421141345) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "demos", force: :cascade do |t|
t.string "video"
t.string "description"
t.string "name"
end

create_table "ingredients", force: :cascade do |t|
t.integer "volume1"
t.string "volume2"
Expand Down Expand Up @@ -65,6 +71,7 @@
t.inet "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "role"
t.index ["email"], name: "index_users_on_email", unique: true, using: :btree
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end
Expand Down
5 changes: 3 additions & 2 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
User.create(first_name: "Briana",
last_name: "West",
email: "bmwest@bu.edu",
password: "123456")
password: "123456",
role: "admin")


@description = []
Expand Down Expand Up @@ -60,7 +61,7 @@
"Nectarine Muffins",
"Oatmeal Raisin Cookie Muffins",
"Orange Yogurt Bread",
"Peachy Banana Muffins",,
"Peachy Banana Muffins",
"Sour Cream, Cheddar, and Chive Biscuits",
"Sour Cream Cinnamon Streusel Muffins with Pecan Filling",
"Southwest Style Egg Muffins",
Expand Down