【发布时间】:2013-12-04 05:12:19
【问题描述】:
我一直在使用ranked model 并关注此sortable tables tutorial。
我为此烦恼不已,任何人都可以提供帮助的任何事情都很棒!
我有Decks,其中有很多Cards。在套牌编辑页面上,我正在尝试对其自己的套牌进行排序。
card.rb
belongs_to :deck
include RankedModel
ranks :row_order, :with_same => :deck_id
routes.rb
resources :decks do
post :sort, on: :collection
resources :cards
end
decks_controller.rb
def sort
@deck = Deck.find(params[:id])
@deck.update_attributes(deck_params)
@deck.save
render nothing: true
end
def deck_params
params.require(:deck).permit(:name, :id, :cards_attributes => [:id, :question, :answer, :deck_id, :_destroy, :row_order, :row_order_position])
end
jquery
$.ajax({
type: 'POST',
url: $(this).data('update_url'),
dataType: 'json',
data: { id: deck_id, deck: { cards_attributes: { row_order_position: position } }}
这一切都在 Rails 4 上。 我认为问题在于我如何发布数据。
我已经检查了卡片本身的row_order,它正在设置中。我似乎无法理解如何使用嵌套的cards_attributes 通过 ajax 传递信息。
我也不确定为什么教程在 ajax 帖子中显示 row_order_position: position,而我认为它只是 row_order: position。
【问题讨论】:
标签: jquery ruby-on-rails ajax jquery-ui ruby-on-rails-4