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

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

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 < ActiveRecord::Ba...

Read more

Tips: Multiple pagination with will_paginate

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

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 &lt;%= will...

Read more

Different layout for the same controller

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

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 => 'stan...

Read more

Rails Best Practices 6: Filters and helpers file

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

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

Read more

Partial Validation in Rails

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

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

Read more

Rails Authlogic + Subdomain_fu Template

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

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

Read more