class AddDefaultMigration < ActiveRecord::Migration
def self.up
change_column :tasks, :status, :string, :default => default_value, :null => false
end
end
also
https://github.com/bsm/attribute-defaults
Thursday, 13 September 2012
rails migration set defaults
Wednesday, 12 September 2012
simple datetimepicker in rails
http://www.jakoblaegdsmand.com/blog/2012/05/simple-datetimepicker-in-rails
caller
See full stack flow of execution ..very useful for debugging
c =caller.join("\n <br/>")
render :text => c
/Users/yanniskolovos/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/Users/yanniskolovos/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/abstract_controller/base.rb:167:in `process_action'
/Users/yanniskolovos/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_controller/metal/rendering.rb:10:in `process_action'
/Users/yanniskolovos/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
/Users/yanniskolovos/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-
and so on
c =caller.join("\n <br/>")
render :text => c
/Users/yanniskolovos/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/Users/yanniskolovos/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/abstract_controller/base.rb:167:in `process_action'
/Users/yanniskolovos/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_controller/metal/rendering.rb:10:in `process_action'
/Users/yanniskolovos/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
/Users/yanniskolovos/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-
and so on
tap
each element
[1,2,3,4,5].each {|a| a.tap {|t| p t + 10}}
=>
11
12
13
14
15
Tap the array
[1, 2, 3].tap(&:reverse!)
=> [3, 2, 1]
unique Relationship
class Relationship < ActiveRecord::Base
belongs_to :entry
belongs_to :tag
validates :tag_id, :uniqueness => { :scope => :entry_id }
end
Thursday, 6 September 2012
Faker::?
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
\Faker\Address::address(); | |
\Faker\Address::streetName(); | |
\Faker\Address::streetAddress($includeSecondary = false); | |
\Faker\Address::city(); | |
\Faker\Address::state(); | |
\Faker\Address::stateAbbr(); | |
\Faker\Address::zipCode(); | |
\Faker\Address::zip(); | |
\Faker\Address::postcode(); | |
\Faker\Address::cityStateZip(); | |
\Faker\Address::country(); | |
\Faker\Company::name(); | |
\Faker\Company::suffix(); | |
\Faker\Company::catchPhrase(); | |
\Faker\Company::bs(); | |
\Faker\DateTime::timestamp(); | |
\Faker\DateTime::date($format = null); | |
\Faker\DateTime::dateFormat(); | |
\Faker\DateTime::time($format = null); | |
\Faker\DateTime::timeFormat(); | |
\Faker\DateTime::dateTime($format = null); | |
\Faker\DateTime::dateTimeFormat(); | |
\Faker\DateTime::month(); | |
\Faker\DateTime::monthAbbr(); | |
\Faker\DateTime::weekday(); | |
\Faker\DateTime::weekdayAbbr(); | |
\Faker\Internet::email($name = null); | |
\Faker\Internet::freeEmail($name = null); | |
\Faker\Internet::safeEmail($name = null); | |
\Faker\Internet::userName($name = null); | |
\Faker\Internet::domainName(); | |
\Faker\Internet::safeDomainName(); | |
\Faker\Internet::domainWord(); | |
\Faker\Internet::domainSuffix(); | |
\Faker\Internet::ipv4Address(); | |
\Faker\Internet::slug($str = null, $glue = array('.', '-', '_')); | |
\Faker\Lorem::word(); | |
\Faker\Lorem::words($num = 3); | |
\Faker\Lorem::sentence($wordCount = 4); | |
\Faker\Lorem::sentences($sentenceCount = 3); | |
\Faker\Lorem::paragraph($sentenceCount = 3); | |
\Faker\Lorem::paragraphs($paragraphCount = 3); | |
\Faker\Name::name(); | |
\Faker\Name::firstName(); | |
\Faker\Name::lastName(); | |
\Faker\Name::prefix(); | |
\Faker\Name::suffix(); | |
\Faker\PhoneNumber::phoneNumber(); | |
\Faker\PhoneNumber::safePhoneNumber(); |
Tuesday, 4 September 2012
heroku-accounts
Or you can choose a fully-automated approach:
$ heroku accounts:add work --auto
Enter your Heroku credentials.
Email: work@example.org
Password: ******
Generating new SSH key
Generating public/private rsa key pair.
Your identification has been saved in ~/.ssh/identity.heroku.work.
Your public key has been saved in ~/.ssh/identity.heroku.work.pub.
Adding entry to ~/.ssh/config
Adding public key to Heroku account: work@example.org
To switch an app to a different account:
# in project root
heroku accounts:set personal
To list accounts:
$ heroku accounts
personal
work
To remove an account:
$ heroku accounts:remove personal
Account removed: personal
Set a machine-wide default account:
$ heroku accounts:default personal
To clone a git repository from Heroku, change 'heroku.com' to the Host of the desired account defined in your .ssh/config:
$ git clone git@heroku.work:repository.git
If you want to switch the account for an app:
$ heroku accounts:set work
This also changes the URL of the git origin heroku
to make sure you're using the correct SSH host.
https://github.com/ddollar/heroku-accounts
rake db production
Production environment in localhost
rake db:migrate RAILS_ENV="production"
RAILS_ENV=production bundle exec rake assets:precompile
rails s -e production
for heroku:
heroku create --stack cedar
Subscribe to:
Posts (Atom)