Archive for March, 2011

19
Mar
11

rails 406 error code when using ajax


I kept receiving a 406 error code when trying to use ajax in a rails app. The problem was that in the request’s Accept header, text/javascript wasn’t included, and this caused the error.
Additionally, I think this may have had something to do with it:

– I was submitting a form when on a select’s onChange handler, by using:


this.form.submit();

I changed it to :


$("#myform").submit();

I’m not really sure if this influenced it in someway, but I said, if I’m still using jQuery to do things, better use it to do everything.

17
Mar
11

rails single table inheritance


I’ve been struggling a little with single table inheritance in Rails. I think I got the concept. You have one big table which has all the attributes all of your models will need. Based on the validations of each model, you’ll end up having all the correct data for every model you have.

Make sure:

  1. You have a type column, of type String in your base model table
  2. You inherit your models from your base model
  3. Each specific model does the validations it needs

An example can be found here.

15
Mar
11

simple client side validations using validator


You can find here a nice comprehensive article on simplifying your client side form validations.

Add this to your page:



  $(document).ready(function() {
    $('#form_id').validator();
  });

and it will automatically validate your form when you try to submit it.

09
Mar
11

accessing form helpers from the console


Include this:

include ActionView::Helpers::FormOptionsHelper

I used this to test the collection_select method in the console.

09
Mar
11

accessing the routing helpers from the console


If you want to have access to the routing helpers from the console, start the console by running:

rails console

and then write:

include ActionController::UrlWriter




Blog Stats

  • 216,750 hits