orbit-basic/app/controllers/admin/snippets_controller.rb

102 lines
2.5 KiB
Ruby
Raw Normal View History

class Admin::SnippetsController < ApplicationController
layout "admin"
# GET /snippets
# GET /snippets.xml
def index
@snippets = Snippet.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @snippets }
end
end
# GET /snippets/1
# GET /snippets/1.xml
def show
@snippet = Snippet.find(params[:id])
redirect_to "/#{@snippet.name}"
end
# GET /snippets/new
# GET /snippets/new.xml
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|
@snippet.write_attribute( "content_#{locale}", "<ul>\n#{lis}</ul>" )
end
2009-05-22 07:16:22 +00:00
end
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @snippets }
end
end
# GET /snippets/1/edit
def edit
@snippet = Snippet.find(params[:id])
end
# POST /snippets
# POST /snippets.xml
def create
@snippet = Snippet.new(params[:snippet])
respond_to do |format|
if @snippet.save
flash[:notice] = 'Snippet was successfully created.'
format.html { redirect_to admin_snippets_url }
format.xml { render :xml => @snippet, :status => :created, :location => @snippets }
else
format.html { render :action => "new" }
format.xml { render :xml => @snippet.errors, :status => :unprocessable_entity }
end
end
end
# PUT /snippets/1
# PUT /snippets/1.xml
def update
@snippet = Snippet.find(params[:id])
respond_to do |format|
if @snippet.update_attributes(params[:snippet])
flash[:notice] = 'Snippet was successfully updated.'
format.html { redirect_to admin_snippets_url }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @snippet.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /snippets/1
# DELETE /snippets/1.xml
def destroy
@snippet = Snippet.find(params[:id])
@snippet.destroy
respond_to do |format|
format.html { redirect_to admin_snippets_url }
format.xml { head :ok }
end
end
end