更新後のレンダリングを、RJSに移譲する。
controller
# item_controller.rb
def create
@item = Item.new(params[:item])
respond_to do |format|
if @item.save
format.js # <- create.js.rjs
end
end
end
rjs
/* * id:items の要素の下部(:bottom)に、 * @item(:object => @item)をレンダリングした部分テンプレート"item"の結果を * 挿入する。 * "items"がtbodyなどの要素だと、行挿入になる。 */ page.insert_html(:bottom, "items", :partial => "item", :object => @item)
0 件のコメント:
コメントを投稿