links/app/controllers/admin/web_resources_controller.rb

60 lines
1.4 KiB
Ruby

class Admin::WebResourcesController < OrbitAdminController
before_action ->(module_app = @app_title) { set_variables module_app }
before_action :set_link, only: [:edit, :update, :destroy]
def index
@tags = @module_app.tags
@categories = @module_app.categories.enabled
@filter_fields = filter_fields(@categories, @tags)
@table_fields = [:status, :category, :title]
@links = WebLink.order_by(sort).with_categories(filters("category")).with_tags(filters("tag")).with_status(filters("status")).page(params[:page]).per(10)
if request.xhr?
render :partial => "index"
end
end
def new
@tags =@module_app.tags
@categories = @module_app.categories.enabled
@statuses = []
@link = WebLink.new
end
def create
link = WebLink.new(link_params)
link.create_user_id = current_user.id
link.update_user_id = current_user.id
link.save
redirect_to admin_web_resources_path
end
def edit
@tags =@module_app.tags
@categories = @module_app.categories.enabled
@statuses = []
end
def update
@link.update_attributes(link_params)
@link.save
redirect_to admin_web_resources_path
end
def destroy
@link.destroy
redirect_to admin_web_resources_path
end
private
def set_link
@link = WebLink.find(params[:id])
end
def link_params
params.require(:web_link).permit!
end
end