Thursday 13 September 2012

rails migration set defaults


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

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

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

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