From c650bee03937bd0e741e701f1fe0bfe5cf8e040e Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 12 Aug 2018 07:10:16 -0400 Subject: Add link entry type --- app/controllers/admin/links_controller.rb | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 app/controllers/admin/links_controller.rb (limited to 'app/controllers') diff --git a/app/controllers/admin/links_controller.rb b/app/controllers/admin/links_controller.rb new file mode 100644 index 0000000..bda0d49 --- /dev/null +++ b/app/controllers/admin/links_controller.rb @@ -0,0 +1,52 @@ +class Admin::LinksController < Admin::AdminController + before_action :set_section + + def index + @links = Link.order(created_at: :desc) + end + + def new + @link = Link.new + end + + def create + @link = Link.new(link_params) + + if @link.save + flash.notice = "Link created successfully!" + + render :edit + else + flash.alert = "Error creating link." + + render :new + end + end + + def edit + @link = Link.find(params[:id]) + end + + def update + @link = Link.find(params[:id]) + + if @link.update_attributes(link_params) + flash.notice = "Link updated successfully!" + else + flash.alert = "Error updating link." + end + + render :edit + end + + private + + def link_params + params.require(:link).permit(:title, :url, :tag_list, records_attributes: [:description, :_destroy]) + end + + def set_section + @section = "links" + end + +end -- cgit 1.4.1