Skip to content

Instantly share code, notes, and snippets.

@rocodev-tech
rocodev-tech / products_controller.rb
Created July 10, 2015 00:29
app/controllers/products_controller.rb
class ProductsController < ApplicationController
def index
end
end
@rocodev-tech
rocodev-tech / application.html.erb
Created July 7, 2014 07:46
artstore / app / views / layouts / application.html.erb
<!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>
rails c
u = User.new(:email=> “xxx@xxx.com”,:password => “12345678”, 
:password_confirmation => “12345678”)
u.save
u.is_admin = true
u.save
@rocodev-tech
rocodev-tech / user.rb
Created July 7, 2014 07:42
artstore / app / models / user.rb
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
@rocodev-tech
rocodev-tech / application_controller.rb
Created July 7, 2014 07:42
app/controllers/application_controller.rb
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
@rocodev-tech
rocodev-tech / products_controller.rb
Created July 7, 2014 07:38
app/controllers/admin/products_controller.rb
class Admin::ProductsController < ApplicationController
def new
@product = Product.new
end
def create
@product = Product.new(product_params)
if @product.save
@rocodev-tech
rocodev-tech / new.html.erb
Last active August 29, 2015 14:03
app/views/admin/products/new.html.erb
<%= 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 %>
@rocodev-tech
rocodev-tech / routes.rb
Created July 7, 2014 07:33
config/routes.rb
Rails.application.routes.draw do
namespace :admin do
resources :products
end
end
@rocodev-tech
rocodev-tech / dev.rake
Created June 29, 2014 18:07
lib/tasks/dev.rake
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
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!