From 8e15dbd73035c2a2198a2828a20ddcebe0739823 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 3 Jul 2018 13:58:57 -0400 Subject: Implemented streams Currently there are no links to the pages for editing stream updates, and the admin panel for managing streams could probably have a better look & feel, but here's some basic working functionality. refs #8 --- app/controllers/admin/updates_controller.rb | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 app/controllers/admin/updates_controller.rb (limited to 'app/controllers/admin/updates_controller.rb') diff --git a/app/controllers/admin/updates_controller.rb b/app/controllers/admin/updates_controller.rb new file mode 100644 index 0000000..9bf9caf --- /dev/null +++ b/app/controllers/admin/updates_controller.rb @@ -0,0 +1,52 @@ +class Admin::UpdatesController < Admin::AdminController + before_action :set_section + + def new + @stream = Stream.find(params[:stream_id]) + @update = @stream.updates.build + end + + def create + @stream = Stream.find(params[:stream_id]) + @update = @stream.updates.build(update_params) + + if @update.save + flash.notice = "Update created successfully!" + + render :edit + else + flash.alert = "Error creating update." + + render :new + end + end + + def edit + @stream = Stream.find(params[:stream_id]) + @update = Update.find(params[:id]) + end + + def update + @stream = Stream.find(params[:stream_id]) + @update = Update.find(params[:id]) + + if @update.update_attributes(update_params) + flash.notice = "Update updated successfully!" + else + flash.alert = "Error updating update." + end + + render :edit + end + + private + + def update_params + params.require(:update).permit(:body, records_attributes: [:description, :_destroy]) + end + + def set_section + @section = "streams" + end + +end -- cgit 1.4.1