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:
I have a lot of code in my project like the following:
class Animal < ActiveRecord::Base
around_transition :on => :sure do |animal, _, block|
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
class Member < ActiveRecord::Base
Resque.enqueue BadNewsWorker, id
raise('surprise') # real world :(
band = Band.create
band.destroy # => RuntimeError
Band.count => 1
More under the cut
You can refactor template's code with
= mail_to 'email@example.com', '<i class="icon-envelope"></i><span>Email</span>'.html_safe, class: 'secondary', encode: 'hex'
- name = capture do
= mail_to 'firstname.lastname@example.org', name, class: 'secondary', encode: 'hex'
Very useful :)
Ruby on Rails API
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
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:
Personal RSS available by
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.
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
I changed my #regexp to
/\A[а-яё]+\z/, but it doesn't look great.
Is there another solution?
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) ->
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
But we can cheat a little and do the following thing:
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
But what about
This syntax doesn't raise any errors and returns boolean
"foo" !=~ /foo/ # => true
"foo" !=~ /asd/ # => true
Does anybody can explain me how it works?
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
select abilities.* from abilities order by
(case when available then 1 when available is null then 2 else 3 end) asc
3 and then sorts by integers.
Do you know another solution?
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
env.rb file and stub whatever you want :)