Say you're using pgvm
to manage several versions of Postgres and you need to install the PostGIS extension.
$ brew uninstall postgis
$ pgvm install 9.3.12
$ pgvm use 9.3.12
$ pgvm cluster create my_cluster
$ pgvm cluster start my_cluster
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 example:
class SomeModel
#attributes: :name, :body, :some_group_key
end
class SomeModelSerializer
attributes :name
end
# in controller
def index
@some_models = SomeModel.all.group_by(&:some_group_key)
render json: @some_models, each_serializer: SomeModelSerializer
end
So this w...
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").
Solution: Define custom methods on the class:
# replacement for .first/.last because we use uuids
def self.first
order("users.created_at").first
end
def self.last
order("users.created_at DESC").first
end
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 Flags Refs Use Netif Expire
default 192.168.1.3 UGSc 131 0 en6
127 127.0.0.1 UCS 0 0 lo0
127.0.0.1 127.0.0.1 UH 9 448 lo0
127.94.0.1 127.94.0...
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).count(:id_column) working.
If you try to do the following:
Article.group(:visible_to_readers).count(:id)
And you have a default scope on your model:
class Article < ActiveRecord::Base
default_scope -> { order(published_at: :desc) }
end
Then you will get the f...
javascript: (function ($) {
var branchName = "nothing found" ;
var story = jQuery(".ghx-fieldname-issuekey a");
if(story){
var title = $("[data-field-id='summary']").text();
var id = story.text();
var translate = {
"ä": "ae", "ö": "oe", "ü": "ue", "ß": "ss"
};
var storyType = "feature";
var commitMessage = "[" + id + "] " + title;
prompt('Your commit message:', commitMessage);
} else {
alert("Please select the stories first.");
}
})(jQuery);
javascript: (function ($) {
var branchName = "nothing found" ;
var story = jQuery(".ghx-fieldname-issuekey a");
if(story){
var title = $("[data-field-id='summary']").text();
var id = story.text();
var translate = {
"ä": "ae", "ö": "oe", "ü": "ue", "ß": "ss"
};
var cleanedTitle = title.toLowerCase().replace(/[öäüß]/g, function(match) {
return translate[match];
}).replace(/[^a-zA-Z0-9]+/g, "_").replace(/^_/, "").replace(/_$/, "");
var cleanedId = id.toUpperCase().replace(/[öäüß]/g, fun...
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
Packets Pings
Host Loss% Snt Last Avg Best Wrst StDev
1. 216.239.48.53 0.0% 69 24.9 32.0 24.8 88.8 12.5
64.233.174.55
209.85.246.205
2. ???
3. google-public-dns-a.google...
To use different Facebook apps for authentication with Devise and OmniAuth:
# config/initializers/devise.rb
config.omniauth :facebook, nil, nil, setup: true
# config/routes.rb
match '/auth/:provider/setup' => 'sessions#setup'
def setup
# in this example facebook keys for different site domai...
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');
collapsed = false;
}
stories.each(function () {
var story = $(this);
var title = (collapsed ? story.find('.story_name').text() : story.find('.editor.name').val());
var id = /story_(\d+)/.exec(story.attr('class'))[1];
var gitptTitle = '[#' + id + '] ' +...
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 storyType = story.find(".story_type .selection").text();
var gitptTitle = id + '-' + title;
var translate = {
"ä": "ae", "ö": "oe", "ü": "ue", "ß": "ss"
};
var cleanedTitle = storyType + "/" + gitptTitle.toLowerCase().replace(/[öäüß]/g, function(match) {
return translate[...
Use __send__
:
where{__send__(dynamic_column_name) = '42'}
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 new records get created with the right user_id allready set:
001: > Power.new(@user).creatable_books
=> #<Book id: nil, title: nil, description: nil, user_id: 189, created_at: nil, updated_at: nil>
002:> # Note that the above record has the user_id set.
BUT
When you now implement so...
If there's any HTML in your I18n string, remember to add "_html" to its name.
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 so made it public. Compare also the Gatekeeping: Guide for gatekeeper card.
In order to reduce the number of rejects we get from clients, we want to review all code written before it goes to the staging serv...