As we know we don't see scrolls on #OSX Lion and above by default,
but sometimes we have to show them to user because of #UX.
We can do it just by adding scroll's styles. For example:
#myelement::-webkit-scrollbar {
-webkit-appearance: none;
width: 8px;
}
#myelement::-webkit-scrollbar-track {
background-color: #eee;
border-radius: 8px;
}
#myelement::-webkit-scrollbar-thumb {
border-radius: 8px;
background-color: #666;
}
#html
I have a lot of code in my project like the following:
class Animal < ActiveRecord::Base
state_machine do
around_transition :on => :sure do |animal, _, block|
animal.transaction do
block.call
animal.do_things_on_sure
end
end
end
end
around_transition looks ugly and repeats for many classes.. Lets refactor it. More under the cut
Here is a typical bad case in #rails:
class Band < ActiveRecord::Base
has_many :members, dependent: :destroy
end
class Member < ActiveRecord::Base
belongs_to :band
after_destroy do
Resque.enqueue BadNewsWorker, id
raise('surprise') # real world :(
end
end
band = Band.create
band.members.create
band.destroy # => RuntimeError
Band.count => 1
More under the cut
You can refactor template's code with capture method:
/ before:
li
= mail_to 'info@gistflow.com', '<i class="icon-envelope"></i><span>Email</span>'.html_safe, class: 'secondary', encode: 'hex'
/ after:
li
- name = capture do
i class="icon-envelope"
span Email
= mail_to 'info@gistflow.com', name, class: 'secondary', encode: 'hex'
Very useful :)
Ruby on Rails API
#rails
When you wanna create a simple triangle you probably don't want to create a new image, then create a double-sized version for retina and so on..
There is a solution for triangles - css borders. They can be used for creating any triangles you need :) More under the cut
On http://mailtrap.io you can sign up and register a mailbox.
Then you get an email config's setup for development env.
All emails will be sent to mailtrap and it won't be delivered to real users. It is very important when you have a real db for development.
This service is absolutely free.
#rails #email #tests
State Machine comes to the rescue when models in your application need statuses and events.
There is a #state_machine gem for #ruby.
I recommend you to spend some time studying basics before you start using it with #rails. More under the cut
Besides link_to, form_for with remote: true you can get the same behaviour with any inputs.
Let's take a look at the source code of jquery-rails: More under the cut
Thanks Mr. @SqREL for the pull request.
You can subscribe to public RSS by this link: http://gistflow.com/all.
Personal RSS available by http://gistflow.com/users/username.
I had not use RSS before and I wonder how to render posts in it? More under the cut
The old way to do menu like this:

was using single row table with fixed width.
The problem is because we can't create dynamic width of menu item without table or javascript...
But there is a solution. More under the cut
I found the following:
# coding: utf-8
alphabet = "абвгдеёжзийклмнопрстуфхцчшщэюя" # (russian cyrillic)
alphabet =~ /\A[а-я]+\z/ # => nil
For some reason [а-я] doesn't include ё character.
I changed my #regexp to /\A[а-яё]+\z/, but it doesn't look great.
Is there another solution?
#ruby
Just wrap your inputs with <div data-max-values="3">...</div> and add the following #js
$('div[data-max-values]').on 'change :checkbox', ->
condition = $(':checked', @).length >= Number($(@).data('max-values'))
$(':not(:checked)', @).prop 'disabled', condition
$('div[data-max-values]').each (i, e) ->
$(':checkbox:first', e).trigger('change')
#query required.
#html #forms
When we add, for example, a new validation, write test for that and deploy the code you still can broke website because of old database data.
Not only validations can do that, so we need to check what will happens. More under the cut
When you migrated to #poltergeist you see annoying plain html debug when use save_and_open_page..
But we can cheat a little and do the following thing:
# env/test.rb
config.action_controller.asset_host = "http://jour_project.dev"
# or "http://0.0.0.0:3000" for example
Now you will get html generated in test env and assets from development env. Useful!
#rails #capybara #phantomjs
So we know about a =~ operator.
But what about !=~?
This syntax doesn't raise any errors and returns boolean true value..
"foo" !=~ /foo/ # => true
"foo" !=~ /asd/ # => true
Does anybody can explain me how it works?
#ruby
What will we do until Xmas? Of course we will prepare for it!
Let's print Xmas tree by your favourite language!
All winners will get a present ;) More under the cut
Here is a trick I have found:
Assume we have a table abilities with field available.
select abilities.* from abilities order by
(case when available then 1 when available is null then 2 else 3 end) asc
It replaces true as 1, null as 2 and false as 3 and then sorts by integers.
Do you know another solution?
#sql
Gem #omniauth provides some special methods for tests.
Let me show you how to test #rails application with omniauth registration.
First, tell OmniAuth about your env.
# test.rb (env)
OmniAuth.config.test_mode = true
More under the cut
In order to stub objects in #cucumber's step definitions like you do with #rspec specs just add
require 'cucumber/rspec/doubles'
to cucumber env.rb file and stub whatever you want :)