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

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

Read more

Two step signup with Devise

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

[** UPDATE: 21/01/2013 **]: Thanks to Kevin Triplett now there's a Devise wiki page referencing this post and combining the comments. Please check this wiki page, especially if you’re using Rails 3 and Devise 2: https://github.com/plataformatec/devise/wiki/How-To:-Email-only-sign-up On my Ruby on Rails projects I usually use the Devise gem for user authentication. In the last application I need to customize Devise so that users can register p...

Read more

Prevent registration of reserved login

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

Every time you create a web application where users can register, it is good to exclude some login or username so that they can not be used. A classic example is the login "admin". I believe that no one wishes that in its application will be a registered user...

Read more

Ruby Enumerables: Operation on hashes

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

In my last post I talked about Ruby's hash. Today I will resume and complete the argument by describing some of the things you can do to manipulate the hash values. 1. How to iterate over Hash elements The Ruby Hash class provides three different iterators: each, each_key, each_value. There is actually a fourth iterator, each_pair but it is only an alias of each. As you can expect the each iterator works as follows: {"company" => "DevInterface", "a...

Read more

Ruby Enumerables: Hashes

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

The most famous framework based on Ruby language, Ruby on Rails, makes extensive use of hash. And cause in our blog we talk mainly about development with Ruby on Rails it seem fair to me to explore some language constructs that are widely used by the ...

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 that prompts for an SSL connection. As often happens with Ruby On Rails, the solution is quite simple. You just need ...

Read more