This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Account < ActiveRecord::Base | |
| scope :scope1, where("domain in('bit', 'bite')") | |
| scope :scope2, where("custom_domain = 'bites'") | |
| end | |
| >> Account.scope1.scope2.to_sql | |
| => "SELECT \"accounts\".* FROM \"accounts\" WHERE (domain in('bit', 'bite')) AND (custom_domain = 'bites')" | |
| >> Account.scope2.scope1.to_sql | |
| => "SELECT \"accounts\".* FROM \"accounts\" WHERE (custom_domain = 'bites') AND (domain in('bit', 'bite'))" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def create | |
| @my_thing = MyThing.create(params[:my_thing]) | |
| respond_to do |format| | |
| format.json { @my_thing.to_json } | |
| end | |
| end | |
| $(document).ready(function() { | |
| var $list = $('#list'), | |
| $form = $('#my_form'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'jsmin' | |
| require 'aws/s3' | |
| require 'yui/compressor' | |
| task :deploy => ['deploy:console'] | |
| namespace :deploy do | |
| task :console => :environment do | |
| if Rails.env != 'production' | |
| puts "We need to be running in production environment, ie 'rake RAILS_ENV=production deploy'" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $.fn.tagList = function() { | |
| return this.each(function() { | |
| var $orginal = $(this), | |
| $input = $('<input type="text">'), | |
| $button = $('<button class="add_tag">Add</button>'), | |
| $tag_list = $('<ul class="tags" />'), | |
| $suggestions = $orginal.parents('form').find('div.popular.tags'), | |
| current_value = $orginal.val(); | |
| $orginal.parent() | |
| .addClass('taggings') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AutoCompleteController < ActionController::Metal | |
| def search_queries | |
| sql = "SELECT name FROM tags WHERE name #{like_operator} #{quote(params['q']+'%')} LIMIT 10" | |
| render ActiveRecord::Base.connection.select_values(sql).to_json | |
| end | |
| def tags | |
| sql = "SELECT value | |
| FROM search_queries |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Setting for open or closed tags by default | |
| # Rails Core seems to think XHTML is cool, hard coded defaults and all | |
| module ActionView::Helpers | |
| module TagHelper | |
| mattr_accessor :default_tags_to_open | |
| self.default_tags_to_open = false | |
| def tag(name, options = nil, open = ActionView::Helpers::TagHelper.default_tags_to_open, escape = true) | |
| "<#{name}#{tag_options(options, escape) if options}#{open ? ">" : " />"}".html_safe |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Setting for open or closed tags by default | |
| module ActionView::Helpers | |
| module TagHelper | |
| mattr_accessor :default_tags_to_open | |
| self.default_tags_to_open = false | |
| def tag(name, options = nil, open = ActionView::Helpers::TagHelper.default_tags_to_open, escape = true) | |
| "<#{name}#{tag_options(options, escape) if options}#{open ? ">" : " />"}".html_safe | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $.fn.appForm = function() { | |
| return this.each(function() { | |
| var $search = $('<input type="search">'), | |
| $button = $('<button>Search</button>'), | |
| $result_container = $('<div id="app_search_result" />'), | |
| $app_list = $('#apps'); | |
| var $app_form = $(this).after($search, $button, $result_container).detach(); | |
| $search.data('search_context', 'local'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var $search = $('<input type="search">'), | |
| $button = $('<button>Search</button>'), | |
| $result_container = $('<div id="app_search_result" />'), | |
| $app_list = $('#apps'); | |
| var $app_form = $(this).after($search, $button, $result_container).detach(); | |
| $search.data('search_context', 'local'); | |
| $search |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| apps_controller: | |
| def search | |
| @query = params[:query] | |
| @search = App.search(@query) | |
| respond_with(@search) | |
| end | |
| app.rb: | |
| class << self |