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:1234567891011121314151617181920212223242526272829303132cla...

Read more

Different layout for the same controller

In some projects can happen that you have to use different graphic templates for different methods of the same controller. At first sight one would implement a solution that provides an explicit call to the desired layout within each action.Something like this:123456789101112131415161718192021class PostController < ApplicationController def index [...] :layout => 'standard' end def show [...] :layout => 'standard' end def new [...] :la...

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

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

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 terms of code tha...

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

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

Read more