Skip to content

Instantly share code, notes, and snippets.

View overture8's full-sized avatar

Phil McClure overture8

  • Stora
  • Belfast, Northern Ireland
View GitHub Profile
class Company < ActiveRecord::Base
has_many :addresses
end
class Address < ActiveRecord::Base
belongs_to :company
end
class Company < ActiveRecord::Base
has_many :addresses
accepts_nested_attributes_for :addresses, :allow_destroy => true
end
<% 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 />
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 October 7, 2009 12:15
Unobtrusively observe a form with prototype
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({
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
<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>
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
common: &common
solr:
hostname: localhost
port: 8983
production:
<<: *common
solr:
path: /data/solr/myapp
// ***** 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