From 616a0d2d2ba15a7e176938ee829d60366fb6a9c2 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sun, 9 Aug 2026 13:26:23 +0200 Subject: Attach an asset to a page from the asset's own page The picker moves from assets/edit to assets/show, where the list of attached pages already is. A member route, POST assets/:id/attach_to_node, replaces the ride on #update. Supersedes the picker wiring in the previous commit; what remains of it is @attach_node in #create, the flash composition and the corrected hint. --- app/controllers/assets_controller.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'app/controllers/assets_controller.rb') diff --git a/app/controllers/assets_controller.rb b/app/controllers/assets_controller.rb index e58f4f30..4b27d1c4 100644 --- a/app/controllers/assets_controller.rb +++ b/app/controllers/assets_controller.rb @@ -38,7 +38,6 @@ class AssetsController < ApplicationController # GET /assets/1/edit def edit @asset = Asset.find(params[:id]) - @attach_node = Node.not_in_trash.find_by(:id => params[:node_id]) if params[:node_id].present? end # POST /assets @@ -69,7 +68,6 @@ class AssetsController < ApplicationController # PUT /assets/1.xml def update @asset = Asset.find(params[:id]) - @attach_node = Node.not_in_trash.find_by(:id => params[:node_id]) if params[:node_id].present? respond_to do |format| if @asset.update(asset_params) @@ -102,6 +100,20 @@ class AssetsController < ApplicationController end end + # POST /assets/1/attach_to_node + def attach_to_node + @asset = Asset.find(params[:id]) + node = Node.not_in_trash.find_by(:id => params[:node_id]) + + if node + attach_to(node) + else + flash[:error] = t("flash.assets.attach_no_node") + end + + redirect_to(asset_path(@asset)) + end + private def asset_params -- cgit v1.3