Skip to content

Instantly share code, notes, and snippets.

@jhjguxin
jhjguxin / rails_template_for_mongoid.rb
Created June 11, 2012 02:10 — forked from huacnlee/rails_template_for_mongoid.rb
A custom Rails template for Mongoid.
# coding: utf-8
# This is a Rails init template with MongoDB projects
#
# Mongoid, Devise, Bootstrap, jQuery, Redis, Cells, will_paginate, Carrierwave, simple_form, Settingslogic, Thin
#
# Usage
#
# $ rails new app_name -m https://raw.github.com/gist/2168014
#
@jhjguxin
jhjguxin / bootstrap_and_overrides.css.less.erb
Created June 11, 2012 13:15
work with less or scss and rails
#############################################################
#the begin time I want use bootswatch, to encjoy multi theme which base on bootstrap,so I install some gem necessary
#Gemfile
gem "twitter-bootstrap-rails", "~> 2.1.0"
gem "less-rails-bootswatch", "~> 0.2.5"
#This gem is meant to be used with bootstrap-sass.
#gem "bootswatch-rails", "~> 0.0.11"
#bootstrap_and_overrides.css.less.erb
@jhjguxin
jhjguxin / seed_date_from_yml.rb
Created June 12, 2012 09:01
seed date from yml
#tag.yml
#encoding: utf-8
妈妈:
备孕:
孕前检查
孕前营养
孕前调理
受孕时机
备孕心理
不孕不育
@jhjguxin
jhjguxin / load_config.rb
Created June 12, 2012 09:02
load_config_from_yml
#In summary:
# config/initializers/load_config.rb
#APP_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/config.yml")[RAILS_ENV]
# application.rb
#if APP_CONFIG['perform_authentication']
# Do stuff
#end
@jhjguxin
jhjguxin / _form.html.erb
Created June 15, 2012 02:34
rails ajax demo base on BBTangCMS
<%= simple_form_for @knowledge, :html => { :class => 'form-horizontal', :class => "form-inline", :remote => true } do |f| %>
<div class="knowledge-head box">
<span class="label label-info">head</span>
<%= f.input :title %>
<%= f.input :summary, :input_html => { :rows =>"3", :cols =>"50" } %>
<!--%= f.input :content %-->
</div>
<div class="knowledge-content box">
<span class="label label-info">content</span>
<%= f.input :body, :as => :kindeditor, :input_html => { :width => 850, :height => 500 } %>
@jhjguxin
jhjguxin / Gemfile
Created June 15, 2012 05:22
sina and tqq(open.t.qq.com) oauth2 base on bbtang relation gist is gist: 3865157
gem "weibo2", "~> 0.1.0"
gem "tqq2", :git => "git://github.com/jhjguxin/tqq2.git"
gem "connect-qq", :git => "git://github.com/jhjguxin/connect-qq.git"
@jhjguxin
jhjguxin / migration.rb
Created June 18, 2012 09:43
tag迁移 -- Andersen_Fan
# in db
update knowledges set auto_tags = tags;
update questions set auto_tags = tags;
alter table tags rename to tags_bak;
rake db:migrate
#TODO? for identity/timeline/category tags?
# in rails console
class TagBak < ActiveRecord::Base
@jhjguxin
jhjguxin / rescue_catch.rb
Created June 19, 2012 03:17
ruby Exception catch
begin
# something which might raise an exception
rescue SomeExceptionClass => some_variable
# code that deals with some exception
rescue SomeOtherException => some_other_variable
# code that deals with some other exception
else
# code that runs only if *no* exception was raised
ensure
# ensure that this code always runs, no matter what
@jhjguxin
jhjguxin / konwledge.js
Created June 19, 2012 07:35
Kindeditor ajax post for Ruby on Rails
_form.html.erb
<%= f.input :body, :width => 850, :height => 500 %>
refresh.js.erb
$("#edit_<%= dom_id @knowledge %>").replaceWith("<%= render 'refresh_form'%>");
$("#new_knowledge").replaceWith("<%= render 'refresh_form'%>");
var editor = KindEditor.create(
'textarea[id="knowledge_body"]',
{
@jhjguxin
jhjguxin / Rakefile
Created June 20, 2012 05:26
how to resque
#No such file to load -- devise/confirmations_controller
#resque worker devise not eager loading
require File.expand_path('../config/application', __FILE__)
require 'rake/dsl_definition'
require 'resque/tasks'
Askjane::Application.load_tasks
task "resque:setup" => :environment do