Sunday, May 25, 2014

Share language files from a rails plugin

If you want to share you language file from with the plugin. Then you need to add the local files in the auto load path in the engine file like following,

module Commission
class Engine < ::Rails::Engine
config.i18n.load_path += Dir[config.root.join('config', 'locales', '**', '*.{rb,yml}')]
end
end
view raw commission.rb hosted with ❤ by GitHub

Tuesday, March 11, 2014

Faster capistrano deploy with skipping bundler and asset precompilation

If you guys use git then you can use the following script in you deploy.rb to override the default behavior if asset pre compilation and bundle install.
namespace :bundler do
desc "Install bundles into application"
task :install, :roles => [:app] do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} Gemfile Gemfile.lock | wc -l").to_i > 0
run "cd #{latest_release} && #{try_sudo} bundle install --without test"
else
logger.info "Skipping Bundle install because there were no asset changes"
end
end
end
namespace :deploy do
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
end
end
view raw gistfile1.rb hosted with ❤ by GitHub

Sunday, February 9, 2014

Twitter bootstrap 3 typeahead SCSS

.twitter-typeahead .tt-query,
.twitter-typeahead .tt-hint {
margin-bottom: 0;
}
.tt-dropdown-menu {
@extend .dropdown-menu;
}
.tt-suggestion {
display: block;
padding: 3px 20px;
}
.tt-suggestion.tt-is-under-cursor {
color: $dropdown-link-active-color;
background-color: $dropdown-link-active-bg;
}
.tt-suggestion.tt-is-under-cursor a {
color: #fff;
}
.tt-suggestion.tt-cursor {
color: $dropdown-link-active-color;
background-color: $dropdown-link-active-bg;
}
.tt-suggestion p {
margin: 0;
}
.twitter-typeahead {
width: 100%;
input {
border: none;
}
}
view raw gistfile1.scss hosted with ❤ by GitHub

Tuesday, June 18, 2013

Allow mongo to connect from remote IP

Access to mongo is controlled with iptables for Linux based OS.

Step 1

Make sure in your /etc/mongodb.conf file you have the following line,
bind_ip = 0.0.0.0

Step 2

Add iptables rules to control the incoming and outgoing traffic for mongo. Here is a sample command if you have the default ports for mongo.

$ sudo iptables -A INPUT -s 198.61.168.XXX,166.78.113.XX -p tcp 
--destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
$ sudo iptables -A OUTPUT -d 198.61.168.XXX,166.78.113.XX -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT

Here 198.61.168.XXX and 166.78.113.XX are the IP from where you want to access the mongodb.

Sunday, May 12, 2013

Readable model name with translation support

Use following to have the translated attribute with fallback support,
Person.human_attribute_name("first_name") # => "First name"
view raw gistfile1.txt hosted with ❤ by GitHub
This will look in to the translation in the following order,
en:
attributes:
first_name: First name
activerecord:
models:
person:
first_name: First name
view raw gistfile1.txt hosted with ❤ by GitHub
First it will look for the "en.activerecord.models.person.first_name" and then for "en.attributes.first_name" and finally falls back to humanize.