因此,我使用jquerys可排序來對嵌套表單域進行排序。這裏的控制方法它提交時,它的排序以:通過可分類嵌套表格不能保存的參數
def sort_questions
params[:questions_attributes].to_a.each_with_index do |id, index|
question = Question.find(id)
question.position = index + 1
question.save(:validate => false)
end
render :nothing => true
end
下面是獲得在Chrome看着我檢查通過PARAMS:
"questions_attributes"=>{"1"=>{"content"=>"Where did you grow up?", "position"=>"", "_destroy"=>"false", "id"=>"2"}, "0"=>{"content"=>"What are you doing?", "position"=>"", "_destroy"=>"false", "id"=>"3"}}
下面是被呼叫的jQuery的排序功能:
$('#questions').sortable({
items:'.fields',
placeholdet: true,
axis:'y',
update: function() {
$.post("/templates/#{@template.id}/sort_questions?_method=post&" + $('.edit_template').serialize());
}
});
位置屬性不保存。我一遍又一遍嘗試了各種各樣的sort_questions方法,沒有運氣。
任何幫助將是偉大的。謝謝!
下面是完整的PARAMS:
"template"=>{"name"=>"Long Term Volunteer Opportunity", "description"=>"This template will be for opportunities that are for long term missionaries.", "default"=>"1", "questions_attributes"=>{"0"=>{"content"=>"What are you doing?", "position"=>"", "_destroy"=>"false", "id"=>"3"}, "1"=>{"content"=>"Where did you grow up?", "position"=>"", "_destroy"=>"false", "id"=>"2"}}}
查看我在帖子末尾添加的更改。現在它工作正常。謝謝! – Marc 2012-02-07 00:03:12