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 ProductsController < ApplicationController | |
def index | |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Artstore</title> | |
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> | |
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> | |
<%= csrf_meta_tags %> | |
</head> | |
<body> |
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
rails c | |
u = User.new(:email=> “[email protected]”,:password => “12345678”, :password_confirmation => “12345678”) | |
u.save | |
u.is_admin = true | |
u.save |
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 | |
def admin? | |
is_admin |
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 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 | |
current_user.admin? | |
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 Admin::ProductsController < ApplicationController | |
def new | |
@product = Product.new | |
end | |
def create | |
@product = Product.new(product_params) | |
if @product.save |
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 [:admin, @product] do |f| %> | |
<div class="group"> | |
<%= f.label("標題") %> | |
<%= f.text_field :title %> | |
</div> | |
<div class="group"> | |
<%= f.label("敘述") %> | |
<%= f.text_area :description %> |
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
Rails.application.routes.draw do | |
namespace :admin do | |
resources :products | |
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
namespace :dev do | |
desc "Rebuild system" | |
task :build => ["tmp:clear", "log:clear", "db:drop", "db:create", "db:migrate", "db:seed" ] | |
desc "demo" | |
task :demo => :environment do | |
for i in 1..10 do | |
puts i | |
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 OrderPlacingService | |
def initialize(cart,order) | |
@order = order | |
@cart = cart | |
end | |
def place_order! | |
@order.build_item_cache_from_cart(@cart) | |
@order.calculate_total!(@cart) | |
@cart.clear! |
NewerOlder