Orbit/app/controllers/admin/snippets_controller.rb

70 lines
1.5 KiB
Ruby
Raw Normal View History

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
2009-05-22 07:16:22 +00:00
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
2009-07-06 08:23:34 +00:00
VALID_LOCALES.each do |locale|
2010-01-08 07:45:13 +00:00
@snippet.send( :write_attribute, "content_#{locale}", "<ul>\n#{lis}</ul>" )
2009-07-06 08:23:34 +00:00
end
2009-05-22 07:16:22 +00:00
end
2010-01-04 09:49:55 +00:00
end
def edit
@snippet = Snippet.find(params[:id])
end
def create
@snippet = Snippet.new(params[:snippet])
2010-01-04 09:49:55 +00:00
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])
2010-01-04 09:49:55 +00:00
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
2010-01-04 09:49:55 +00:00
redirect_to admin_snippets_url
end
2010-01-04 09:49:55 +00:00
end