{{toc}}
- 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
<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)) |
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] | |
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 |
# This command will list all table in a rails app in rails console | |
ActiveRecord::Base.connection.tables |
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 |
# 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: |
#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 = {} |