Skip to content

Instantly share code, notes, and snippets.

View baothi's full-sized avatar

Nguyễn Bảo Thi baothi

View GitHub Profile
@baothi
baothi / application.rb
Created April 1, 2016 07:30
sủ dụng gem grape để viết api
#config/application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Foundations
@baothi
baothi / _form.html.haml
Created November 19, 2015 17:35
ung dung js.erb
= form_for [:admins, @admins_product], remote: true do |f|
- if @admins_product.errors.any?
#error_explanation
%h2= "#{pluralize(@admins_product.errors.count, "error")} prohibited this admins_product from being saved:"
%ul
- @admins_product.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :name
@baothi
baothi / index.html.haml
Last active November 4, 2015 15:02
làm CRUD trong 1 file index
= form_for [:admins,@admins_product] do |f|
- if @admins_product.errors.any?
#error_explanation
%h2= "#{pluralize(@admins_product.errors.count, "error")} prohibited this admins_product from being saved:"
%ul
- @admins_product.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :name
class Admins::ApplicationController < ApplicationController
layout 'layouts/admins'
before_action :authenticate_admin!
# def authenticate_admin!
# return render_404 unless current_user.is_admin?
# end
end
@baothi
baothi / heder.rb
Last active September 1, 2015 02:13
%nav.navbar.navbar-default
.container
/ Brand and toggle get grouped for better mobile display
.navbar-header
%button.navbar-toggle.collapsed{"aria-expanded" => "false", "data-target" => "#bs-example-navbar-collapse-1", "data-toggle" => "collapse", :type => "button"}
%span.sr-only Toggle navigation
%span.icon-bar
%span.icon-bar
%span.icon-bar
%a.navbar-brand{:href => "#"} Brand
class Admin::Admin < ActiveRecord::Base
attr_accessor :remember_token, :activation_token, :reset_token
before_save :downcase_email
before_create :create_activation_digest
has_many :microposts
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, length: { maximum: 255 },
class Admin::AdminController < ApplicationController
authorize_resource :class => false
layout "admin"
end
<%= form_for(@product) do |f| %>
<% if @product.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>
<ul>
<% @product.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.5'
# Use mysql as the database for Active Record
gem 'mysql2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/home/thinb/.rvm/rubies/ruby-2.2.0/bin/ruby -r ./siteconf20150330-23351-di5g3p.rb extconf.rb
checking for rb_thread_blocking_region()... no
checking for sys/select.h... yes
checking for poll.h... yes
checking for sys/epoll.h... yes
checking for sys/event.h... no
checking for port.h... no
checking for sys/resource.h... yes