Tag Archives: forms

Uploadify – Limit to One Upload Only

Hey everyone,

Just a quick post detailing how to limit uploadify to a single file. Simply add the following settings to your uploadify initialisation:

multi: false
queueSizeLimit : 1
uploadLimit : 1

$(document).ready(function() {
        'swf' : 'Html->url('/uploadify/uploadify.swf');?>',
	'uploader' : 'Html->url('/uploadify/uploadify.php');?>',
	'cancelImg' : 'Html->url('/webroot/uploadify/cancel.png');?>',
	'folder' : 'Html->url('/extraz/uploaded_by_all_users');?>',
	'auto' : true,
	'buttonText' : 'Browse',
	'multi' : false,
	'queueSizeLimit' : 1,
	'uploadLimit' : 1,
	'sizeLimit' : 1073741824,
	'debug' : true,
	'multi' : false,	        
	'onUploadProgress' : upload_progress_handler,
	'onUploadStart' : upload_start_handler,
	'onUploadSuccess' : on_upload_success,
	'onUploadError' : on_upload_error

Once the upload limit is exceeded the onUploadError event is raised.


POST 406 (Not Acceptable) – AJAX with Ruby on Rails

Just a quick post on an error I ran into today when trying to create an AJAX image upload with Ruby on Rails. When submitting an AJAX form I received the following error:

POST 406 (Not Acceptable)

It turns out that there is a fairly simple (and admittedly obvious) solution. Ensure that your controller has an appropriate response for JavaScript files:


{:multipart => true}, :remote => 'true') do |f| %>

prohibited this image from being saved:

  • 'button' %>
    @upload.product_id %>

    Form JavaScript:

    /* Wait for document to load */
    $(document).ready(function() {
    /* Create an ajax form */
    function create_ajax_form(form_id){
       //Handle ajax submission
       $j('#' + form_id).submit(function(){
           //Send for data
           $j.post($j(this).attr("action"), $j(this).serialize(), null, "script");
           //Return false
           return false;

    Controller Action:

    #Create an upload
      def create
        #Create vars
        @upload = Upload.new(params[:upload])
        #Create responses
        respond_to do |format|
          if @upload.save
            #Retrieve product
            @product = Product.find_by_id(@upload.product_id)
            #Create success responses
            format.html { redirect_to @product, :notice => 'Image Added Successfully!'}
            #Create error responses
            format.html { render :action => 'new'}

    JavaScript Response:


    Popover Function – Twitter Bootstrap

    Just a quick post on how easy it is to implement a popover with twitter bootsrap:


    //Create tooltips for login/signup forms
    function create_tooltips(){
        //Create vars
        var titles = ['test title']
        var contents = ['test content'];
        var fields = ['#user_email'];
        //Loop through each field and assign tooltip
        for(var i = 0; i < fields.length; i++){
            //Create vars
            var field = $(fields[i]);
            var title = titles[i];
            var content = contents[i];
            //Ensure field found
                //Create popover
                        animation: true,
                        placement: 'right',
                        selector: false,
                        trigger: 'hover',
                        title: title,
                        content: content,
                        delay: 0


    resource_name, :url => registration_path(resource_name), :class => 'form-vertical') do |f| %>
    'btn btn-success' %>


    Popover - Twitter Bootstrap

    Popover - Twitter Bootstrap

    That’s all there is to it, if you haven’t had a chance to check it out yet make sure you head on over to the official site – there are some pretty neat features.

    undefined method `merge’ for 5:Fixnum – Hidden Field

    Just a quick post on an error I ran into today while using hidden fields:

    undefined method `merge' for 5:Fixnum
    28: 'button' %> 29:
    30: 31: 32:

    Thankfully this is an easy fix, simply amend your code as follows:

    'button' %>
    @upload.product_id %>

    And that’s all there is to it, let me know if there are any issues.

    Submit form_for to Custom Action – Ruby on Rails

    Just another quick problem I ran into with rails this afternoon – how to submit a form_for to a custom action. Luckily there’s quite a bit on how to do this in the documentation, my solution ended up as follows:

     url_for(:controller => 'feedbacks', :action => 'leave_seller_feedback') do |f| %>

    Just substitute your form_for tag with the one above and put in the relevant details and it should all work fine. Keep in mind that the submit tag doesn’t need to be changed, just the form_for tag.