How to implement dependent dropdowns in Rails 4 with an unobtrusive jQuery script

I recently had to implement a view with the classic search form with two select dependent on each other. My aim was to leave the page as clean as possible and make the code that loads the options for the daughter dropdown reusable.Suppose, therefore, to have two models, SpecializationType and Specialization, defined as follows:1234567891011121314151617181920212223242526272829303132class SpecializationType...

Read more

Tips: Multiple pagination with will_paginate

Will Paginate is a great and widely used gem for pagination in Ruby on Rails.Sometimes you need to paginate multiple list on the same page.This tip show you how to put a list of paginated products and a list of of paginated services on the same page with will_paginate. The key point is to use a custom param param_name in the view and also in the controllerThe view code is something like this:123# ... # products list here &...

Read more

How to send email asynchronously using Devise and Rails3

Hello everyone.I’d show a workaround to send email asynchronously using Devise and Rails3.Suppose we have already up and running our application with Devise and delayed_job correctly installed.A first attempt was to add in config/initializers the following file (devise_async.rb):12345678910111213141516#devise_async.rb module Devise module Models module Confirmable handle_asynchronously :send_confirmation_instructions end module Recoverable ...

Read more

Rails Best Practices 6: Filters and helpers file

With the today’s post I shall conclude my series on Ruby On Rails Best Practices . This is not because the required topics are completed, but rather because after the release of Rails 3.0, some constructs have been changed and should be reviewed. Probably in future we will return to talk about best practices, but starting from the new features introduced in the current Rails version. Bu...

Read more

Rails Best Practices 5: Optimize Migration

Migrations, in my opinion, are one of the best things in Rails since these allow the creation and populating the database using ruby code without having to worry about which type of db run below. That said, even writing the migration is better to follow some best practices. 1. DB Index The first practice I strongly recommend is to define indices for the external keys and for all those columns on which you will make sort, search and groups. Let’s take a sampl...

Read more

The top 20 plugins to create a Rails application

Rails is now closer to its official third release and all plugins and gems authors are working to ensure compatibility of their products with the new version of the framework.Among the many Rails plugins released by the community, I make a list of 20 most used (and useful) in our projects at DevInterface.Authentication Authlogic: this plugin is definitely the more common among Rails 2.x applications. It was releases as releas...

Read more

Rails Authlogic + Subdomain_fu Template

The second free Rails startup skeleton written by DevInterface and releases under Rails MIT license is Rails Authlogic + Subdomain_fu Template.Rails Authlogic + Subdomain_fu TemplateThis template works as a skeleton for any new Rails application (using Rails 2.3) that aims to provide authentication with subdomain support.To install and run this template perform fol...

Read more