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

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

Read more

How to send email asynchronously using Devise and Rails3

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

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
Ruby on Rails and jQuery: multiselect with checkbox

Ruby on Rails and jQuery: multiselect with checkbox

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

Today I want to present a very convenient jQuery plugin I’ve used to create a combo box with checkboxes for a multi-selection field.Suppose we have a form of insertion / modification of user data, and that the user can have multiple functions. We start with rendering the form with a multi-selection field, where you can select more functions with the combination “<ctrl> + click “.123456789101112<%= simple_form_for(@user) do |f| %> <%= f.label :password %> <%= f.password_field :pass...

Read more

How-to send email with a Google account form Ruby On Rails

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

I have seen many articles in the web that explain how to send an email with a Google account from a Ruby On Rails application. However, I believe there are several faulty or incomplete examples around. That’s why I decided to share a working solution that I used in various projects.The main problem with Gmail (or with an address linked to Google Apps) is th...

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 => 'standard' e...

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

Read more