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:12345678910111213...

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 modul...

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. But now I will describe two techniques that are valid and which are mainly related to code organization...

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 sample mig...

Read more

Rails Best Practices: introduction

I’ve decided to dedicate a series of posts to Rails Best Practices because I think it is important to share in order to continuously improve the way you write programs.Write these posts will also be an opportunity for me to investigate my knowledge, so I invite you right now to follow this trip with me and contribute with your comments.This first post is just an introduction in which I want to highlight the advantages of writing Ruby on Rails applications following the Best Practices rul...

Read more

Partial Validation in Rails

It happens sometimes that you have to implement creation or editing of a model splitted on more than one form. A classic case is a registration form divided into two steps or a guided wizard with several pages.This situation presents us with a problem: when and how to validate data?The first idea that may come to mind is simply to leave it all validations in the last page when you go to create or update the model. But this is also the least elegant solutions, both in ...

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 release replacement for the ...

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 following actions:12345git clone git://githu...

Read more