Skip to content

Instantly share code, notes, and snippets.

Phil McClure overture8

Block or report user

Report or block overture8

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View accepts_nested_attributes_for.rb
class Company < ActiveRecord::Base
has_many :addresses
accepts_nested_attributes_for :addresses, :allow_destroy => true
end
View fields_for.html.erb
<% form_for setup_company(@company) do |f| %>
<%= f.label :name %><br />
<%= f.text_field :name %><br />
<% f.fields_for :addresses do |address_form| %>
<%= f.label :street %><br />
<%= address_form.text_field :street %><br />
<%= f.label :city %><br />
<%= address_form.text_field :city %><br />
<%= f.label :post_code %><br />
View inherit_from_employee.rb
class FullTimeEmployee < Employee
end
temp_employee.rb
class TempEmployee < Employee
end
student_employee.rb
View app_helper.rb
module ApplicationHelper
def setup_company(company)
returning(company) do |c|
c.addresses.build if c.addresses.empty?
end
end
end
@overture8
overture8 / unobtrusive_observe_form.js
Created Oct 7, 2009
Unobtrusively observe a form with prototype
View unobtrusive_observe_form.js
var ObserveForm = Class.create({
initialize: function() {
this.form = $('form_id');
this.form.observe('submit', this.submitForm.bindAsEventListener(this));
this.data_area = $('display_area');
},
submitForm: function(event) {
event.stop();
this.form.request({
View search_results.rhtml
<h2>Your results</h2>
<% unless @results.nil? %>
<table>
<tr>
<th>company</th>
<th>profile</th>
</tr>
<% for result_item in @results %>
<tr class="<%= cycle('odd', 'even') %>">
<td><%= result_item.name %></td>
View sunspot_indexing.rb
class Company < ActiveRecord::Base
# Sunspot/Solr search indexing
searchable do
string :name
text :profile
integer :media_type_id
integer :sector_type_id, :multiple => true do
sectors.map {|sector| sector.sector_type_id}
end
end
View sunspot_search.rb
def search_results
search = Company.search do
keywords 'belfast marketing'
with(:sector_type_id).any_of [1, 2, 4, 8]
paginate :page => page_number, :per_page => 30
order_by :name, :asc
end
@results = search.results
end
View sunspot.yml
common: &common
solr:
hostname: localhost
port: 8983
production:
<<: *common
solr:
path: /data/solr/myapp
View raindrop.sass
// ***** Raindrop Theme
!base_color_1 = #1C1D21
!base_color_2 = #31353D
!base_color_1_light = !base_color_1 + #212121
!base_color_1_lighter = !base_color_1 + #444444
!base_color_1_dark = !base_color_1 - #111111
!base_color_2_light = !base_color_2 + #212121
!base_color_2_lighter = !base_color_2 + #444444
You can’t perform that action at this time.