Skip to content

Instantly share code, notes, and snippets.

<script type="text/javascript">
$(document).ready(function(){
var manualuploader = new qq.FineUploader({
callbacks : {
onComplete : function(id, name, response) {
}
},
element : $('#<%= type%>_manual-fine-uploader')[0],
validates_format_of :review_website_link, :with => URI::regexp(%w(http https))

Ruby on Rails coding standard

{{toc}}

Code style

  • Use UTF-8. It’s 21 century, 8bit encodings dead now.
  • Use 2 space indent, not tabs
  • Use Unix-style line endings
  • Keep lines not longer than 80 chars
@harssh
harssh / validate_unique_combination_of_multiple_columns_in_rails.rb
Created October 27, 2013 16:33
Rails: Validate unique combination of multiple columns
The validation syntax where multiple columns combination is validated for uniqueness is :
validates_uniqueness_of :column_namae1, :scope => [:column_name2, :column_name3]
or even shorter in ruby 1.9.x:
validates_uniqueness_of :column_name1, scope: [:column_name2, :column_name3]
@harssh
harssh / install_postgres_on_ubuntu.txt
Created October 28, 2013 16:52
Install PostgreSQL 9.1 on Ubuntu 13.04 Linux
Step 1: Install PostgreSQL on your system
Run the following commands in your console:
sudo apt-get update
sudo apt-get install postgresql-9.1
Step 2: Configure your postgresql password
sudo -u postgres psql template1
module MyApp
class Application < Rails::Application
require Rails.root + 'lib/custom_public_exceptions'
config.exceptions_app = CustomPublicExceptions.new Rails.public_path
end
end
@harssh
harssh / table_list.rb
Created November 20, 2013 04:35
List all tables in rails app using console
# This command will list all table in a rails app in rails console
ActiveRecord::Base.connection.tables
@harssh
harssh / rails_console_sandbox.rb
Created November 20, 2013 04:38
command to open rails console in sandbox
The Sandbox
Sometimes it would be nice to open up a console session and mess around with the data to see what happens. But if you do that, the data’s messed up. The solution to that is to lunch the console with the --sandbox flag. When launched, you can handle the data, tweak it, and destroy it, all without fear of harming any of your data.
Rails Console Sandbox
rails console --sandbox
Loading development environment in sandbox (Rails 3.2.1)
Any modifications you make will be rolled back on exit
@harssh
harssh / ransack.rb
Created November 22, 2013 11:34 — forked from ledermann/ransack.rb
# Patch for ransack (https://github.com/ernie/ransack) to use scopes
# Helps migrating from Searchlogic or MetaSearch
# Place this file into config/initializer/ransack.rb of your Rails 3.2 project
#
# Usage:
# class Debt < ActiveRecord::Base
# scope :overdue, lambda { where(["status = 'open' AND due_date < ?", Date.today]) }
# end
#
# Ransack out of the box ignores scopes. Example:
@harssh
harssh / gist:7598651
Created November 22, 2013 11:46 — forked from meinac/gist:7222298
#paste this code in your ransack.rb initializer
#if you want to use scopes on search or sort please use Class.ransack_with_scopes instead of Class.search
Ransack::Adapters::ActiveRecord::Base.class_eval do
def ransack(params = {}, options = {}, scope_used_on_sort = false)
Ransack::Search.new(self, params, options, scope_used_on_sort)
end
def ransack_with_scopes(params = {}, options = {})
scope_used_on_sort = false
ransack_scope = self
ransack_params = {}