Skip to content

Instantly share code, notes, and snippets.

background:
linear-gradient( 90deg, white 0%, rgba(255,255,255,0)),
linear-gradient(-90deg, white 0%, rgba(255,255,255,0)) 100% 0,
radial-gradient(
farthest-side at 0% 50%,
rgba(0,0,0,1),
rgba(0,0,0,0.3)
),
radial-gradient(
farthest-side at 100% 50%,
background:
linear-gradient( 90deg, white 0%, rgba(255,255,255,0)),
linear-gradient(-90deg, white 0%, rgba(255,255,255,0)) 100% 0,
radial-gradient(
farthest-side at 0% 50%,
rgba(0,0,0,1),
rgba(0,0,0,0.3)
),
radial-gradient(
farthest-side at 100% 50%,

為什麼用 Ransack

在網站中提供搜尋、篩選與排序功能在現在的網站中已是基本需求,畢竟大家的耐心,在 Ruby on Rails 中,由於採用了 ActiveRecord 作為 ORM 框架的緣故,要快速的組出 Search Query 並非難事。

基本上只要搭配上 Form Object 與 Query Object 模式,要優雅的完成好維護的搜尋模組還算是容易,但當你想要快速完成搜尋功能的時候,Ransack 絕對是你的好夥伴。

基本使用

Basic Configuration

Ransack 的基本設定極其簡單,只要安裝完後基本上就可以使用了。

  • 首先,在你的 Gemfile 中加入:
<style>
.section {
width: 960px;
margin: auto;
border: 1px solid #888;
padding: 40px 0;
}
.clearfix {
clear: both;
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.css">
<style type="text/css">
.item {
margin: 10px;
float: left;
@YushengLi
YushengLi / 4060_remote_control_blynk.ino
Created December 31, 2017 11:20
Remote Control Arduino 4060 Car Over WiFi with self hosted Blynk
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
@YushengLi
YushengLi / led_color_switch.h
Created December 10, 2017 06:32
An Example to switch color of a RGB LED with a button
const byte redPin = 3;
const byte greenPin = 5;
const byte bluePin = 6;
const byte interruptPin = 2;
volatile byte mode = 0;
volatile byte modeChanged = 0;
unsigned long lastInterrupt;
void setup() {
setColourRgb(0,0,0);
@YushengLi
YushengLi / fortigate.rb
Created September 9, 2017 14:07
A dummy script to generate Fortigate Firewall object and Reserved address batch insertion script from CSV
require 'csv'
class Fortigate
def self.export_batch_object_script(path)
File.open('firewall_address', 'w+') do |f|
f.write("config firewall address\n")
f.write(" edit all\n")
f.write(" next\n")
f.write(" edit \"SSLVPN_TUNNEL_ADDR1\"\n")
f.write(" set type iprange\n")
// Remember to add tabindex to <a>
body.no-js {
a.dropdown-toggle:focus {
pointer-events: none;
}
a.dropdown-toggle:focus + .dropdown-menu {
opacity: 1;
visibility: visible;
pointer-events: auto;
}