Fork me on GitHub

green_light, Client Side Validation for Rails

by Phil

Maybe it's me, but there seems to be a severe lack of good client-side validation plugins, which integrate with ActiveModel. So, my employer, Rumble Labs kindly gave me some time to write one of our own, for use with internal projects and personal use.

green_light is a client-side validation gem which makes use of the jQuery Validation Plugin. The beauty of this gem, is that your validation rules are still defined in the model.

Give it a go!

Download green_light

Download jQuery Validation Plugin



Posted on Mon 04 Apr 2011 | Comments

VIM gnome-256color not known

by Phil

This one always troubles me each time I need to re-install Ubuntu. The solution?

 sudo apt-get install ncurses-term

Done.



Posted on Thu 17 Feb 2011 | Comments

Forms Disappeared when upgrading to Rails 3.0.0

by Phil

Just upgraded one of my apps from Rails 3.0.0rc4 to Rails 3.0.0. One issue - all the forms disappeared! After doing some hunting, I found that the issue was being caused by the HAML gem. To fix this, upgrade to the 3.0.18 release of the HAML gem.



Posted on Wed 22 Sep 2010 | Comments

Wildcard Subdomains with Dnsmasq

by Phil

In a previous article, I talked about using subdomains in Rails 3. Since then, many people have elaborated on the topic. There's even been a great Railscast.

I've found Tim Pope's post particularly useful. Basically, he has set up a domain name that resolves to locahost/127.0.0.1. This save you from having to specify subdomains in you /etc/hosts file - which is a hassle!

I'd like to offer another alternative using Dnsmasq. With Dnsmasq, you can set up a simple DNS server locally, then you can use an apache virtual host to deal with wildcard domains.

Install/Configure Dnsmasq

First, install Dnsmasq - I'm using Ubuntu (sorry for those who aren't).

Now, edit the /etc/dnsmasq.conf file:

The listen-address basically defines what IP address Dnsmasq will listen on. In our case this is your local machine.

The address line specifies a lookup for the name blah.localhost. As you can see, this is mapped to your local machine also.

Believe it or not, that's pretty much it! And if you've tried to use Bind for a similar job, you'll be very happy right now.

One more thing though! You need to add 127.0.0.1 as DNS server in your network settings. If you're using linux, edit /etc/resolv.conf and add a new nameserver line to the top:

Finally, restart Dnsmasq:-

 sudo /etc/init.d/dnsmasq restart

Apache Stuff

Now all you need to do is set up a virtual host:

Restart apache and you're done.

Or! If you're Using Rails

If you're using Rails, you won't need to set up a virtual host in Apache. Just start your server:

 rails s

Then browse to the domain you set up, like so:

 http://mysubdomain.blah.localhost:3000

Also, on a seperate note... You may notice internet pages are loading faster. This is because you now have a local DNS server cache. Therefore, resolving domains is a lot faster. You get this as a free side effect.



Posted on Thu 15 Jul 2010 | Comments

Interacting with Controllers via the app object

by Phil

Sometimes it's useful to interact with your controllers via the console. This, as you may know, can be achieved with the app object. You can perform GET, POST, PUT and DELETE requests by doing the following:-

If you need to login to your Rails app first, you will need to send a post request to the controller that creates the user session. Most likely, the "sessions" controller - "create" action. First, you'll need to take a note of the fields that are used for the user name and password on the login form. In my case, this is username and password. Now you're ready to send your post request:

Notice, on the first line, that you need to disable forgery protection. I found that I couldn't log in unless I did this. Another thing that I needed to do, was deal with subdomains. For instance, the user (in my app) should only be allowed to log in when a subdomain is specified. You can do this by setting the "host", as seen on the second line on the code snippet above. If all goes well, you should get a 302 response and you can start interacting with the rest of your applications actions:-

Very handy indeed. Also, getting familiar with these commands is useful for when you're writing functional tests.



Posted on Tue 13 Jul 2010 | Comments
© 2009 Phil McClure This site was developed using Compass, Blueprint and Ruby on Rails - Much thanks to these guys!