Skip to content

Instantly share code, notes, and snippets.

View liangzan's full-sized avatar

Wong Liang Zan liangzan

View GitHub Profile
dev_sqlite:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# in your shell
./script/server -p 3001 -e dev_sqlite
# you should see the same in localhost:3001
@liangzan
liangzan / zsh_rvm_prompt
Created July 26, 2010 10:00
to show rvm in zsh prompt
# add the rvm_info_for_prompt into your prompt
# below is my full prompt
PS1='%{$fg[white]%}%n%{$fg[cyan]%}:%{$fg_no_bold[yellow]%}%3~%{$fg_no_bold[green]%}$(git_info_for_prompt)%{$fg_no_bold[magenta]%}$(rvm_info_for_prompt)%{$reset_color%}# '
# this tests for the presence of rvm
# if its loaded, it'll add the prompt
function rvm_info_for_prompt {
ruby_version=$(~/.rvm/bin/rvm-prompt)
if [ -n "$ruby_version" ]; then
echo "[$ruby_version]"
<% semantic_form_for @post do |form| %>
<%= form.inputs :title, :body %>
<% end %>
class Car < ActiveRecord::Base
composed_of :tyre, :class_name => "Tyre", :mapping => %w(air_pressure wear_and_tear)
composed_of :steering_wheel, :class_name => "SteeringWheel", :mapping => %w(horn)
end
class Child < ActiveRecord::Base
belongs_to :parent
has_one :dog
has_many :toys
has_and_belongs_to_many :schools
end
class Child < ActiveRecord::Base
belongs_to :parent
end
# rails console
>> Child.reflect_on_all_associations
Child.reflect_on_all_associations
=> [#<ActiveRecord::Reflection::AssociationReflection:0xb4828958
@options={},
@collection=false,
# rails console
>> Child.reflect_on_association(:parent)
Child.reflect_on_association(:parent)
=> #<ActiveRecord::Reflection::AssociationReflection:0xb4828958
@options={},
@collection=false,
@name=:parent,
@active_record=Child(id: integer, name: string, parent_id: integer),
@macro=:belongs_to>
class SoccerTeam < ActiveRecord::Base
has_many :players
end
class Player < ActiveRecord::Base
belongs_to :soccer_team
end
# formtastic forms
<% semantic_form_for @soccer_team do |form| %>
<%= form.input :player %>
<% end %>
# the Rails equivalent:
<% form_for @soccer_team do |form| %>
<%= f.select :player, Player.all.collect { |c| c.name, c.id } %>
<% end %>
# lib/formtastic.rb
def select_input(method, options)
...
collection = find_collection_for_column(method, options)
self.select(input_name, collection, strip_formtastic_options(options), html_options)
...
end