Skip to content

Instantly share code, notes, and snippets.

View lscott3's full-sized avatar

Larry Scott lscott3

View GitHub Profile
@lscott3
lscott3 / routes.rb
Created December 20, 2011 03:43
nested resource
scope "/:vanity_url" do
resources :companies, :path => '/clients' do
resources :service_records
end
@lscott3
lscott3 / new.html.erb
Created December 29, 2011 02:38
Nested Resource Problem
<div id='new-category'>
<h4>Add a new category</h4>
<div id="error-space"></div>
<%= form_for([@account.vanity_url, @new_category]) do |cat| %>
<%= cat.text_field :name %>
<%= cat.submit %>
<% end -%>
<%= link_to "Close", "#", :id => "close" %>
</div>
@lscott3
lscott3 / account.rb
Created March 26, 2012 06:21
Builder
class Account < ActiveRecord::Base
belongs_to :package
has_many :users
has_many :clients
has_many :items
has_many :attributes
has_many :notes
accepts_nested_attributes_for :users
accepts_nested_attributes_for :clients
accepts_nested_attributes_for :attributes
class Account < ActiveRecord::Base
has_many :users
authenticates_many :user_sessions, :scope_cookies => true
# Other code by you
end
class UserSessionsController < ApplicationController
def new
@user_session = current_account.user_sessions.build
end
end
@lscott3
lscott3 / application_controller.rb
Created May 17, 2012 02:38
Full Authentication, Authlogic
class ApplicationController < ActionController::Base
helper_method :current_account, :current_user # you may have others that go here too
private
# I added this so that way I can just use current_account just like current_user
def current_account
@current_account = Account.find_by_subdomain(request.subdomain)
return @current_account
@lscott3
lscott3 / application_controller.rb
Created May 17, 2012 02:06
Authlogic application controller
class ApplicationController < ActionController::Base
helper_method :current_account, :current_user # you may have others that go here too
private
# I added this so that way I can just use current_account just like current_user
def current_account
@current_account = Account.find_by_subdomain(request.subdomain)
return @current_account
<%-- This block checks the number of items in a contentloop
---------------------------------------------------------------------------------- --%>
<cms:contentaccess var="content" scope="page" />
<c:set var="count" value="${fn:length(content.valueList['Bottom'])}" />
<%-- End the check
----------------------------------------------------------------------------------- --%>
@lscott3
lscott3 / blank_migration.rb
Created August 1, 2012 15:08
Removing migration data
class CreateAttributes < ActiveRecord::Migration
def change
end
end
@lscott3
lscott3 / maxlength.js
Created October 4, 2012 19:02
maxlength.js
jQuery.fn.limitMaxlength = function(options){
var settings = jQuery.extend({
attribute: "maxlength",
onLimit: function(){},
onEdit: function(){}
}, options);
// Event handler to limit the textarea
var onEdit = function(){