This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/controllers/admin/snippets_controller.rb

70 lines
1.5 KiB
Ruby

class Admin::SnippetsController < ApplicationController
layout "admin"
def index
@snippets = Snippet.all
end
def show
@snippet = Snippet.find(params[:id])
redirect_to "/#{@snippet.name}"
end
def new
@snippet = Snippet.new
if params[:menu]
@snippet.name = "#{params[:menu]}_nav"
lis = Page.find(:all, :conditions => { :parent_page_id => params[:menu], :is_published => true }, :order => "position" ).map do |page|
if page.external_link.blank?
"<li><a href='/#{page.name}'>#{page.name}</a></li>\n"
else
"<li><a href='#{page.external_link}'>#{page.name}</a></li>\n"
end
end
VALID_LOCALES.each do |locale|
@snippet.write_attribute( "content_#{locale}", "<ul>\n#{lis}</ul>" )
end
end
end
def edit
@snippet = Snippet.find(params[:id])
end
def create
@snippet = Snippet.new(params[:snippet])
if @snippet.save
flash[:notice] = 'Snippet was successfully created.'
redirect_to admin_snippets_url
else
render :action => "new"
end
end
def update
@snippet = Snippet.find(params[:id])
if @snippet.update_attributes(params[:snippet])
flash[:notice] = 'Snippet was successfully updated.'
redirect_to admin_snippets_url
else
render :action => "edit"
end
end
def destroy
@snippet = Snippet.find(params[:id])
@snippet.destroy
redirect_to admin_snippets_url
end
end