Sha256: a333ae2453522b605a34602900b4923ad9858a060b7546765321c858914c4d15

Contents?: true

Size: 1.99 KB

Versions: 8

Compression:

Stored size: 1.99 KB

Contents

class Forge::PostsController < ForgeController
  before_filter :get_collections
  before_filter :uses_ckeditor, :only => [:new, :update, :create, :edit]
  load_and_authorize_resource

  def index
    respond_to do |format|
      format.html { @posts = Post.paginate(:per_page => 10, :page => params[:page]) }
      format.js  {
        params[:q] ||= ''
        @posts = Post.where("LOWER(title) LIKE :q OR LOWER(content) LIKE :q", {:q => "%#{params[:q].downcase}%"})
        render :partial => "post", :collection => @posts
      }
    end
  end

  def show
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @post }
    end
  end

  def new
    @post = Post.new
    @help = HelpTopic.where(:slug => "posts_new").first
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @post }
    end
  end

  def edit
  end

  def create
    @post = Post.new(params[:post])

    respond_to do |format|
      if @post.save
        format.html { redirect_to(forge_posts_path, :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

  def update
    params[:post][:post_category_ids] ||= []
    respond_to do |format|
      if @post.update_attributes(params[:post])
        format.html { redirect_to(forge_posts_path, :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

  def destroy
    @post.destroy

    respond_to do |format|
      format.html { redirect_to(forge_posts_path) }
      format.xml  { head :ok }
    end
  end

  private

    def get_collections
      @categories = PostCategory.order(:title)
    end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
forge-cli-0.1.10 lib/forge/app/controllers/forge/posts_controller.rb
forge-cli-0.1.9 lib/forge/app/controllers/forge/posts_controller.rb
forge-cli-0.1.8 lib/forge/app/controllers/forge/posts_controller.rb
forge-cli-0.1.7 lib/forge/app/controllers/forge/posts_controller.rb
forge-cli-0.1.6 lib/forge/app/controllers/forge/posts_controller.rb
forge-cli-0.1.5 lib/forge/app/controllers/forge/posts_controller.rb
forge-cli-0.1.4 lib/forge/app/controllers/forge/posts_controller.rb
forge-cli-0.1.3 lib/forge/app/controllers/forge/posts_controller.rb