Is there a way to reference a Rails ActiveRecord object before it is saved?
I am trying to update a div on a form based on user input (using jQuery). Works fine on edit
because object.id
exists, so I can pass it to the controller action for the jQuery update. In new
there is no object.id
yet, so how can I find the correct object in my controller action?
CONTROLLER...
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_t开发者_如何学Cype').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;
});
});
Thanks in advance for any suggestions!
Just in case anyone else is looking. Ryan Bates shared this with me today via Twitter...
"@patrick_connor Basically you can't. You have to save it first or pass all new attributes around."
精彩评论