Skip to content

Instantly share code, notes, and snippets.

View biagidp's full-sized avatar

David Biagi biagidp

View GitHub Profile
def self.get_options
self.all.collect do |x|
[x.name, x.id]
end
end
#form
<%= form_for [@site, @detail] do |f| %>
<table id='amenities'>
<thead>
<th> Rank </th>
<th> Value </th>
</thead>
<%= f.fields_for :amenities do |af| %>
<tr>
<td><%= af.text_field :rank, :size => 1 %></td>
class Calendar < ActiveRecord::Base
has_many :reservations
end
class Reservation < ActiveRecord::Base
belongs_to :calendar
def self.search(search_fields)
results = self #this is where I'd like to access the collection search was called on
ActionController::Routing::Routes.draw do |map|
map.resources :user_sessions
map.resources :sites, :users
map.resources :sites, :member => { :encode => :get, :decode => :get }
map.login "login", :controller => "user_sessions", :action => "new"
map.logout "logout", :controller => "user_sessions", :action => "destroy"
map.root :login
@biagidp
biagidp / gist:885485
Created March 24, 2011 17:33
Jquery getJSON
$(document).ready(function(){
$('.init').click(function(event){
$.getJSON("http://localhost:37280/sites/1/encode?callback=?", { key: $("#target").attr('value') }, function(data){
alert(data);
});
event.preventDefault();
});
});
Development:
[HomePagesController, ApplicationController, UrlHelper, ActionController::Base, Devise::Controllers::Helpers, TinyMCE::Base, TinyMCE::SpellChecker, #<Module:0x00000001eb2278>, ActionDispatch::Routing::Helpers, #<Module:0x00000002ac2950>, ActiveRecord::Railties::ControllerRuntime, Devise::Controllers::UrlHelpers, ActionController::Compatibility, ActionController::Rescue, ActiveSupport::Rescuable, ActionController::Instrumentation, ActionController::HttpAuthentication::Token::ControllerMethods, ActionController::HttpAuthentication::Digest::ControllerMethods, ActionController::HttpAuthentication::Basic::ControllerMethods, ActionController::RecordIdentifier, ActionController::Streaming, ActionController::RequestForgeryProtection, AbstractController::Callbacks, ActiveSupport::Callbacks, ActionController::Flash, ActionController::Cookies, ActionController::ImplicitRender, ActionController::MimeResponds, ActionController::Caching, ActionController::Caching::Fragments, ActionController::Caching::Config
Dev:
ActionView::Helpers::UrlHelper WAS INCLUDED IN ActionView::Helpers::FormTagHelper!
ActionView::Helpers::UrlHelper WAS INCLUDED IN ActionView::Helpers::FormHelper!
ActionView::Helpers::UrlHelper WAS INCLUDED IN ActionView::Helpers::InstanceTag!
ActionView::Helpers::UrlHelper WAS INCLUDED IN ActionView::Helpers!
ActionView::Helpers::UrlHelper WAS INCLUDED IN ActionView::Base!
ActionView::Helpers::UrlHelper WAS INCLUDED IN ActionView::Base!
ActionView::Helpers::UrlHelper WAS INCLUDED IN ActionView::Base!
@biagidp
biagidp / save_as_draft.rb
Created December 21, 2011 18:10
lib/save_as_draft for rails 3.0
class ActiveRecord::Base
module SaveAsDraft
def save
if self.has_attribute?(:record_status) and self.record_status == "Draft"
super(:validate => false)
else
super
end
end
end
@biagidp
biagidp / save_as_draft.rb
Created December 21, 2011 18:10
lib/save_as_draft for rails 3.0
class ActiveRecord::Base
module SaveAsDraft
def save
if self.has_attribute?(:record_status) and self.record_status == "Draft"
super(:validate => false)
else
super
end
end
end
@biagidp
biagidp / gist:1507541
Created December 21, 2011 20:23
class_eval implementation
require 'active_record'
module SaveAsDraft
ActiveRecord::Base.class_eval do
alias_method :save_without_draft, :save
def save_with_draft
if self.has_attribute?(:record_status) and self.record_status == "Draft"
save_without_draft(:validate => false)
else