Skip to content

Instantly share code, notes, and snippets.

View zachinglis's full-sized avatar

Zach Inglis zachinglis

View GitHub Profile
Interesting.
>> Business.search(:conditions => { :state => "paid" }).length
=> 20
>> Business.find_all_by_state("paid").length
=> 321
@zachinglis
zachinglis / unobtrusive_put_post_links.js
Created August 21, 2008 19:49
Unobtrusively have put and post links
// Examples:
//
// button_to "Mark as unread", mark_as_unread_message_path(message), :method => :put, :class => "form_to_link"
// button_to "New Alert", new_alert
//
jQuery(document).ready(function($) {
var form_to_link = jQuery('.form_to_link');
var form = form_to_link.parents('form');
form.after('<a href="' + form.attr('action') + '" class="button_link_to">' + form_to_link.attr('value') + '</a>');
form.hide();
## django
from django.contrib.auth.models import User
from django.core.validators import email_re
class BasicBackend:
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
def self.authenticate(login, password)
return nil if login.blank? or password.blank?
# need to get the salt
if login.match("@")
user = find_in_state :first, :active, :conditions => { :email => login}
else
user = find_in_state :first, :active, :conditions => { :login => login}
end
<% form_for :listing, @listing, :url => listing_path(@listing), :html => { :method => :put, :class => "edit_post", :id => "edit_post_45" } do |f| %>
## method is still not put as described in the api.
## code
def listing_file=(file)
# self.listing_files.build.attachment = file
self.listing_files.create :attachment => file
self.listing_files.build(:attachment => file)
raise "
#{file}
----
>> a
=> ["joe", "pass"]
>> h = {}
=> {}
>> a.each_with_index do |b, i|
?> h[i] = b
>> end
=> ["joe", "pass"]
>> h
=> {0=>"joe", 1=>"pass"}
## Listing
has_one :residential
delegate :room_desc
## Listing::Residential
## Console
>> listing.room_desc = "This is a room"
=> "This is a room"
ul
list-style-type: none
li
float: left