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
function defaultAjaxErrorHandler(result, isAjaxError) { | |
// do stuff, hide spinner etc... | |
var defaultAjaxError = "Your friendly error message"; | |
var errorToken = "Error:"; | |
if(!isUndefinedOrNull(result) && !isUndefinedOrNull(result.responseText)) { | |
if(result.responseText.startsWith(errorToken)) { | |
// localhost | |
var x = (result.responseText.length > 350) ? 350 : result.responseText.length; | |
alert(result.responseText.substring(0, x) + "...\n\n - Check firebug console for more info.\n - This message for localhost only."); |
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
$j.ajax({ | |
type: "POST", | |
url: "/some_controller/some_action", | |
data: { | |
first_name: $j("#first_name").val(), | |
last_name: $j("#last_name").val(), | |
}, | |
success: function(data, textStatus) { | |
// do what you like | |
}, |
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
<a href="http://www.google.com/" target="_blank">Google</a> |
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
<a href="http://www.google.com/" class="target-blank">Google</a> | |
<script type="text/javascript"> | |
$j(document).ready(function() { | |
$j('a.target-blank').click(function() { | |
this.target = '_blank'; | |
}); | |
} | |
</script> |
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 'net/http' | |
require 'uri' | |
def get_html_content(requested_url) | |
url = URI.parse(requested_url) | |
full_path = (url.query.blank?) ? url.path : "#{url.path}?#{url.query}" | |
the_request = Net::HTTP::Get.new(full_path) | |
the_response = Net::HTTP.start(url.host, url.port) { |http| | |
http.request(the_request) |
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
.pagination { padding: 3px; margin: 3px; } | |
.pagination a { padding: 2px 5px 2px 5px; margin: 2px; border: 1px solid #aaaadd; text-decoration: none; color: #000099; } | |
.pagination a:hover, | |
.pagination a:active { border: 1px solid #000099; color: #000; } | |
.pagination span.current { padding: 2px 5px 2px 5px; margin: 2px; border: 1px solid #000099; font-weight: bold; background-color: #000099; color: #FFF; } | |
.pagination span.disabled { padding: 2px 5px 2px 5px; margin: 2px; border: 1px solid #eee; color: #ddd; } | |
/* From http://workingwithrails.com/railsplugin/4765-will-paginate */ |
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
# see http://gist.github.com/341290 (sort_index_controller_usage.rb) | |
# see http://gist.github.com/341295 (sort_index_view_usage.html.erb) | |
# The classes in this module help to enable sorting on index pages | |
# building sql order clauses and rendering html table header links | |
module SortIndex | |
SORT_KEY_ASC = 'asc' | |
SORT_KEY_DESC = 'desc' | |
SORT_DIRECTION_MAP = { |
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
# see http://gist.github.com/341278 (sort_index.rb) | |
# see http://gist.github.com/341295 (sort_index_view_usage.html.erb) | |
# this example is an employees controller and using the will_paginate plugin | |
# however code should work fine with a standard ActiveRecord#find(:all, :order => ... | |
# put the sort_index.rb code in your rails lib directory | |
class EmployeesController < ApplicationController | |
# index sort constant config for sorting index action | |
# default is order by updated_at DESC |
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
<%- | |
# see http://gist.github.com/341278 (sort_index.rb) | |
# see http://gist.github.com/341290 (sort_index_controller_usage.rb) | |
-%> | |
<table style="width:100%"> | |
<thead> | |
<tr> | |
<%= @sortable.header_link('full_name', 'Name') %> | |
<%= @sortable.header_link('email', 'Email') %> | |
<%= @sortable.header_link('updated_at', 'Updated at') %> |