ActiveRecord::Migration.new.add_column :payments, :card_verification, :string, limit: 8 ActiveRecord::Migration.new.execute "full sql here"
Tech stuff around computer programming, basically for web development, especially opensource. Topics will go round Ruby on Rails (git gems etc.), Ubuntu (admin and basic shell) and work organization (agile philosophy)
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)
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();
Tuesday, 15 May 2012
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=0to 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.
Wednesday, 2 May 2012
define class methods in ruby (private too)
The following syntax could be used for defining the find method itself, but it is mandatory for alias.
class Item
def self.find(name)
# ...
end
class << self
alias :search :find
end
private_class_method :find # writing it below private is not enough
end
Subscribe to:
Posts (Atom)