class PostsController < ApplicationController before_filter :authenticate_admin!, :except => [:show, :cms, :index] # GET /posts # GET /posts.xml def cms @post = Post.find(params[:id]) if(@post.layout != "application") then render :layout => @post.layout end if(@post.template) then render_options[:action] = @post.template render render_options end end def index @posts = Post.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @posts } end end # GET /posts/1 # GET /posts/1.xml def show render_options = {} @post = Post.find(params[:id]) if(@post.layout != "application") then render :layout => @post.layout end if(@post.template!="") then render_options[:action] = @post.template render render_options end end # GET /posts/new # GET /posts/new.xml def new @post = Post.new @categories = Category.find(:all) 1.times do content = @post.contents.build end respond_to do |format| format.html # new.html.erb format.xml { render :xml => @post } end end # GET /posts/1/edit def edit @post = Post.find(params[:id]) end # POST /posts # POST /posts.xml def create @post = Post.new(params[:post]) @post.admin_id = current_admin.id #params[:contents].each do |f| # @post.contents << Content.create(:title=>f[0], :content=>f[1]) #end respond_to do |format| if @post.save format.html { redirect_to(@post, :notice => 'Post was successfully created.') } format.xml { render :xml => @post, :status => :created, :location => @post } else format.html { render :action => "new" } format.xml { render :xml => @post.errors, :status => :unprocessable_entity } end end end # PUT /posts/1 # PUT /posts/1.xml def update @post = Post.find(params[:id]) respond_to do |format| if @post.update_attributes(params[:post]) format.html { redirect_to(@post, :notice => 'Post was successfully updated.') } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @post.errors, :status => :unprocessable_entity } end end end # DELETE /posts/1 # DELETE /posts/1.xml def destroy @post = Post.find(params[:id]) @post.destroy respond_to do |format| format.html { redirect_to(posts_url) } format.xml { head :ok } end end end