Tuesday, 31 July 2012

Change the db with migrations on the fly

What if you want to add a column though the console with one line of code? (and you exactly know what this implies)
ActiveRecord::Migration.new.add_column :payments, :card_verification, :string, limit: 8
ActiveRecord::Migration.new.execute "full sql here"

Saturday, 14 July 2012

Coffescript rendering

The correct way to render html inside your XHR response in Rails.

  app.showFlashMessages('<%=j flash_messages %>')
  $('.booking').replaceWith( '<%=j render @booking %>' )
  app.myFunction( <%=raw array.map(&:to_json) %> ) # TODO: double check

Monday, 4 June 2012

backtrace_silencers to clean the development log from missing assets

# /config/initializers/backtrace_silencers.rb
Rails.backtrace_cleaner.add_silencer { |line| line =~ /lib\/action_dispatch\/middleware\/static.rb/ } if Rails.env.development?

This simple line will clean up your development log to something like this:

[FTL] 
ActionController::RoutingError (No route matches [GET] "/assets/ecoologic/rooms/room_tb.png"):
  actionpack (3.2.5) lib/action_dispatch/middleware/static.rb:62:in `call'

This is only in development (or test?) as you usually don't use the static middleware in staging or production.

Thursday, 17 May 2012

mysql cheatsheet


# Print the query result into a file
mysql> select * into outfile '/tmp/new.txt' from users;

# show the current database
mysql> select database();

Thursday, 3 May 2012

get out of the filter bubble

Google personalizes the results of your query and so do many others. In Google this can be avoided adding
&pws=0
to the end of your search URL in the search bar. Useful for SEO.

Disclaimer: You can't get out of all of the filters bubble.