This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% semantic_form_for @post do |form| %> | |
<%= form.inputs :title, :body %> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Child < ActiveRecord::Base | |
belongs_to :parent | |
has_one :dog | |
has_many :toys | |
has_and_belongs_to_many :schools | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SoccerTeam < ActiveRecord::Base | |
has_many :players | |
end | |
class Player < ActiveRecord::Base | |
belongs_to :soccer_team | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |