Make rails start faster when using Ruby 1.9.2 on a Mac
Related cards:
Gatekeeping: Guide for developer
Note: This has been a private card for some time, because it is heavily tailored to our specific needs and tools. While it will certainly not apply to all (especially larger teams), we thought it might still be helpful as a starting point, and...
be careful when using admin powers with ClassName.active
Very often when using consul, our scopes look something like:
power :creatable_books, :updatable_books, :destroyable_books do
case role
when :user
Book.active.where(user_id: @user.id)
end
end
This is perfect as ...
'PG::GroupingError: ERROR: column must appear in the GROUP BY clause or be used in an aggregate function' in rails while trying ".group"
TL;DR:
If you have an ordering scope on a column of your ActiveRecord model, that must appear in the result set of the group clause. You need to get rid of the scope with ActiveRecord::Base.unscoped to get **SomeArModel.group(:some_column)....
Show the routing table on MacOS
When things get weird with your internet connection and you can't even ping the router's IP, you should have a look at the routing table:
$ netstat -nr
It gives you:
netstat -nr
Routing tables
Internet:
Destination Gateway...
.first and .last on models using uuid
Normally, your rails model is backed by an Integer as ID. So User.first
leads to:
SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
That does not work with UUIDs (e.g. "028edf8c-c61c-40bc-a11c-27e90a7f373c").
Solu...
group_by with ActiveModel::Serializers
When using group_by
in a controller that serializes the grouped collection to JSON you will notice that your serializers created with the active_model_serializer
will not be used and all attributes in your model are just converted to JSON. For...
Use Omniauth/Devise with different Facebook apps (e.g. one for every locale)
To use different Facebook apps for authentication with Devise and OmniAuth:
- Add a setup method to Omniauth that dynamically sets the client id and secret:
# config/initializers/devise.rb
config.omniauth :facebook, nil, nil, setu...
a bookmarklet to generate the branch name from an open pivotal tracker story
javascript: (function ($) {
var storyTitles = [];
var story = $('.story .details').closest('.story').first();
if(story){
var title = story.find('.editor.name').val();
var id = /story_(\d+)/.exec(story.attr('class'))[1];
var s...
a bookmarklet to generate the commit message from an open pivotal tracker story
javascript: (function ($) {
var storyTitles = [];
var stories = $('div.story .selector.selected').closest('.story');
var collapsed = true;
if (stories.length == 0) {
stories = $('div.story .details').closest('.story');
...
mtr says "mtr: unable to get raw sockets"
This is because mtr needs to open raw sockets, which it can only do as root:
$ mtr 8.8.8.8
mtr: unable to get raw sockets.
$ sudo mtr 8.8.8.8
Keys: Help Display mode Restart statistics Order of fields quit
...