2011-02-16 92 views
0

我想基於用戶輸入(使用jQuery)更新窗體上的div。由於object.id存在,因此可以在edit上正常工作,所以我可以將它傳遞給jQuery更新的控制器操作。在new目前還沒有object.id,所以我如何在控制器動作中找到正確的對象? 控制器...有沒有辦法在保存之前引用Rails ActiveRecord對象?

def update_category_select 
    @organization = Organization.find(params[:id]) 
    categories = Category.where(:type => params[:master_type]).order(:name) 
     render :partial => "categories", :locals => {:collection => categories, :organization => @organization} 
    end 

的application.js

$(document).ready(function() { 
    $('#master_type').change(function() { 
    var master_type = $('select#master_type :selected').val(); 
    var id = $('#organization_id').val(); 
    jQuery.get('/organizations/update_category_select/'+ id + '?master_type='+ master_type, function(data){ 
     $("#categories").html(data); 
    }) 
    return false; 
    }); 
}); 

在此先感謝您的任何建議!

回答

0

以防萬一其他人在尋找。 Ryan Bates今天通過Twitter與我分享了這個...

「@patrick_connor基本上你不能,你必須先保存它或者傳遞所有新的屬性。

相關問題