This file contains hidden or 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 AddPriceToProduct < ActiveRecord::Migration | |
| def self.up | |
| add_column :products, :price, :decimal, | |
| :precision => 8, :scale => 2, :default => 0 | |
| end | |
| def self.down | |
| remove_column :products, :price | |
| end | |
| end |
This file contains hidden or 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
| ## /users/edit.html.erb | |
| <% form_for [:cp, @user], :url => { :action => 'update', :id => @user.id } do |f| %> | |
| ... | |
| <%= collection_select :users, :show_id, Show.find(:all), :id, :name, { :prompt => true } %> | |
| ## users_controller.rb | |
| @user.shows << Show.find(params[:users][:show_id]) | |
| ## error | |
| ActiveRecord::AssociationTypeMismatch in Cp/usersController#update |
This file contains hidden or 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 Date | |
| def to_words | |
| today = Date.today | |
| case self | |
| when today | |
| "Today" | |
| when today - 1 | |
| "Yesterday" | |
| when today + 1 |
This file contains hidden or 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 SubscriptionConfirm < ActiveRecord::Base | |
| @@confirm_sent = Hash.new | |
| def initialize(params = nil) | |
| super(params) | |
| set_default_values | |
| end | |
| def self.subscribe_to_newsletter(params = nil) |
This file contains hidden or 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
| desc 'Create YAML test fixtures from data in the existing database.' | |
| task(:extract_fixtures => :environment) do | |
| sql = "SELECT * FROM %s ORDER BY desc(id) LIMIT 10" | |
| skip_tables = ["schema_info", "badges", "badge_groups", "html_links", "hero_plus_status_updates"] | |
| (ActiveRecord::Base.connection.tables - skip_tables).each do |table_name| | |
| i = "000" | |
| File.open("#{RAILS_ROOT}/test/fixtures/#{table_name}.yml", 'w') do |file| | |
| data = ActiveRecord::Base.connection.select_all(sql % table_name) | |
| file.write data.inject({}) { |hash, record| |
This file contains hidden or 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
| Hello, | |
| We are http://whol.ly , an ambitious startup based in NewYork with our | |
| new development centre in Bangalore. While you are reading this, we | |
| are making tiny steps towards innovation in the world of social | |
| networking. Our goal is to let people discover and participate in | |
| their local life by exchanging services, organising events and meeting | |
| new people, all for fun and better living. This brings us into amazing | |
| situation where we are surrounded by interesting engineering problems | |
| which are technologically unique and socially relevant. |
This file contains hidden or 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
| # Original from Mitchell | |
| def self.first_uninteresting | |
| all_numbers = Number.find(:all).map { |entry| entry.number }.sort | |
| last = 0 | |
| all_numbers.each do |number| | |
| if number != last + 1 | |
| return last + 1 | |
| end | |
| last = number |
This file contains hidden or 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
| %a.selected{:href => name, :class => ("selected" if @category == name)} | |
| %span= name |
This file contains hidden or 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
| njero - http://neverlet.be | |
| sutto - http://blog.ninjahideout.com | |
| zapnap - http://blog.zerosum.org | |
| tpope - http://tpope.net | |
| reinh - http://reinh.com | |
| bryanl - http://smartic.us | |
| linoj - http://www.vaporbase.com | |
| technicalpickles - http://technicalpickles.com | |
| MaD15 - enlightsolutions.com/ | |
| qrush - http://litanyagainstfear.com/ |
This file contains hidden or 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
| # http://mozy.com/contest | |
| # Question 4 | |
| # chendo's solution | |
| require 'benchmark' | |
| year = 0 | |
| fibs = [2, 0, 0, 0, 0] # age 0, 1, 2, 3, 4 | |
| adults = 0 # age > 5 | |
| Benchmark.bm do |bm| |
OlderNewer