Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第一週作業! #322

Open
wants to merge 2 commits into
base: store-v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
deploy to heroku
  • Loading branch information
linkevinlin committed Feb 29, 2016
commit dc99757af04709a5d660d8219d2e97d0105b6cf5
11 changes: 9 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
source 'https://rubygems.org'



gem "bootstrap-sass"

gem "devise"
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.2'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
gem 'sqlite3',group: :development
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
Expand All @@ -13,7 +17,11 @@ gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
group :production do
gem "pg"
gem "rails_12factor"

end
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
Expand Down Expand Up @@ -42,4 +50,3 @@ group :development, :test do
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end

31 changes: 31 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.0)
autoprefixer-rails (6.3.3.1)
execjs
bcrypt (3.1.10)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.3.6)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
builder (3.2.2)
byebug (5.0.0)
columnize (= 0.9.0)
Expand All @@ -51,6 +57,13 @@ GEM
coffee-script-source (1.9.1.1)
columnize (0.9.0)
debug_inspector (0.0.2)
devise (3.4.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5)
responders
thread_safe (~> 0.1)
warden (~> 1.2.3)
erubis (2.7.0)
execjs (2.5.2)
globalid (0.3.5)
Expand All @@ -74,6 +87,8 @@ GEM
multi_json (1.11.2)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
orm_adapter (0.5.0)
pg (0.18.4)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
Expand All @@ -96,6 +111,11 @@ GEM
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.2)
loofah (~> 2.0)
rails_12factor (0.0.3)
rails_serve_static_assets
rails_stdout_logging
rails_serve_static_assets (0.0.5)
rails_stdout_logging (0.0.4)
railties (4.2.2)
actionpack (= 4.2.2)
activesupport (= 4.2.2)
Expand All @@ -104,6 +124,8 @@ GEM
rake (10.4.2)
rdoc (4.2.0)
json (~> 1.4)
responders (2.1.1)
railties (>= 4.2.0, < 5.1)
sass (3.4.15)
sass-rails (5.0.3)
railties (>= 4.0.0, < 5.0)
Expand Down Expand Up @@ -132,6 +154,8 @@ GEM
uglifier (2.7.1)
execjs (>= 0.3.0)
json (>= 1.8.0)
warden (1.2.6)
rack (>= 1.0)
web-console (2.1.3)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
Expand All @@ -142,15 +166,22 @@ PLATFORMS
ruby

DEPENDENCIES
bootstrap-sass
byebug
coffee-rails (~> 4.1.0)
devise
jbuilder (~> 2.0)
jquery-rails
pg
rails (= 4.2.2)
rails_12factor
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
spring
sqlite3
turbolinks
uglifier (>= 1.3.0)
web-console (~> 2.0)

BUNDLED WITH
1.11.2
3 changes: 3 additions & 0 deletions app/assets/javascripts/admin/products.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/admin/products.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the admin::products controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
*= require_tree .
*= require_self
*/
@import "bootstrap-sprockets";
@import "bootstrap";
28 changes: 28 additions & 0 deletions app/controllers/admin/products_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Admin::ProductsController < ApplicationController

before_action :authenticate_user!
before_action :admin_required

def index
@products = Product.all
end
def new
@product = Product.new
end

def create
@product = Product.new(product_params)

if @product.save
redirect_to admin_products_path
else
render :new
end
end

private

def product_params
params.require(:product).permit(:title, :description, :quantity, :price)
end
end
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

def admin_required
if !current_user.admin?
redirect_to "/"
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/admin/products_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Admin::ProductsHelper
end
2 changes: 2 additions & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Product < ActiveRecord::Base
end
9 changes: 9 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
def admin?
is_admin
end
end
6 changes: 6 additions & 0 deletions app/views/admin/products/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<ul>
<% @products.each do |product| %>

<li> <%= link_to(product.title, admin_product_path(product)) %> </li>
<% end %>
</ul
25 changes: 25 additions & 0 deletions app/views/admin/products/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%= form_for [:admin, @product] do |f| %>

<div class="group">
<%= f.label("標題") %>
<%= f.text_field :title %>
</div>

<div class="group">
<%= f.label("敘述") %>
<%= f.text_area :description %>
</div>

<div class="group">
<%= f.label("數量") %>
<%= f.text_field :quantity %>
</div>

<div class="group">
<%= f.label("價錢") %>
<%= f.text_field :price %>
</div>

<%= f.submit "Submit", data: { disable_with: "Submitting..." } %>

<% end %>
5 changes: 5 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<%= csrf_meta_tags %>
</head>
<body>
<% if !current_user %>
<%= link_to("登入", new_user_session_path) %>
<% else %>
<%= link_to("登出", destroy_user_session_path, method: :delete) %>
<% end %>

<%= yield %>

Expand Down
25 changes: 0 additions & 25 deletions config/database.yml.example

This file was deleted.

Loading