Sha256: 45cf1f55ad5b37320a7ccb1288e8d756c25e85d7a6d979a2daaf7dae5cf2a009

Contents?: true

Size: 1.99 KB

Versions: 48

Compression:

Stored size: 1.99 KB

Contents

class PostsController < ApplicationController
  before_filter :ensure_logged_in
  before_filter :load_user
  
  def index
    @posts = @user.posts

    respond_to do |format|
      format.html # index.rhtml
      format.xml  { render :xml => @posts.to_xml }
      format.rss do
        headers['Content-Type'] = 'application/rss+xml'
        session[:special] = '$2 off your next purchase'
        session[:special_user_id] = @user.id
        head :ok
      end
    end
  end

  def show
    @post = @user.posts.find(params[:id])

    respond_to do |format|
      format.html { render :layout => 'wide' }
      format.xml  { render :xml => @post.to_xml }
    end
  end

  def new
    @post = @user.posts.build
    render :layout => false
  end

  def edit
    @post = @user.posts.find(params[:id])
  end

  def create
    @post = @user.posts.build(params[:post])

    respond_to do |format|
      if @post.save
        flash[:notice] = 'Post was successfully created.'
        format.html { redirect_to user_post_url(@post.user, @post) }
        format.xml  { head :created, :location => user_post_url(@post.user, @post) }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @post.errors.to_xml }
      end
    end
  end

  def update
    @post = @user.posts.find(params[:id])

    respond_to do |format|
      if @post.update_attributes(params[:post])
        flash[:notice] = 'Post was successfully updated.'
        format.html { redirect_to user_post_url(@post.user, @post) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @post.errors.to_xml }
      end
    end
  end

  def destroy
    @post = @user.posts.find(params[:id])
    @post.destroy
    
    flash[:notice] = "Post was removed"
    
    respond_to do |format|
      format.html { redirect_to user_posts_url(@post.user) }
      format.xml  { head :ok }
    end
  end
  
  private
  
  def load_user
    @user = User.find(params[:user_id])
  end
end

Version data entries

48 entries across 48 versions & 12 rubygems

Version Path
carlosbrando-remarkable-0.0.99 spec/rails_root/app/controllers/posts_controller.rb
emschwar-shoulda-2.0.6.1 test/rails_root/app/controllers/posts_controller.rb
francois-shoulda-2.0.5.1 test/rails_root/app/controllers/posts_controller.rb
francois-shoulda-2.0.5.2 test/rails_root/app/controllers/posts_controller.rb
francois-shoulda-2.0.5.4 test/rails_root/app/controllers/posts_controller.rb
gsterndale-warrant-0.2.0 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.6/test/rails_root/app/controllers/posts_controller.rb
gsterndale-warrant-0.3.0 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.6/test/rails_root/app/controllers/posts_controller.rb
hashrocket-clearance-0.4.0 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.4/test/rails_root/app/controllers/posts_controller.rb
hashrocket-clearance-0.4.1 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.4/test/rails_root/app/controllers/posts_controller.rb
hashrocket-clearance-0.4.2 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.4/test/rails_root/app/controllers/posts_controller.rb
hashrocket-clearance-0.4.3 test/rails_root/vendor/gems/thoughtbot-shoulda-2.0.4/test/rails_root/app/controllers/posts_controller.rb
mattknox-goaloc-0.3.0 lib/goaloc/generators/resources/shoulda/test/rails_root/app/controllers/posts_controller.rb
mattknox-goaloc-0.4.0 lib/goaloc/generators/resources/shoulda/test/rails_root/app/controllers/posts_controller.rb
mjankowski-shoulda-2.0.4 test/rails_root/app/controllers/posts_controller.rb
mjankowski-shoulda-2.0.5 test/rails_root/app/controllers/posts_controller.rb
rmm5t-shoulda-2.0.2 test/rails_root/app/controllers/posts_controller.rb
rmm5t-shoulda-2.0.5 test/rails_root/app/controllers/posts_controller.rb
rmm5t-shoulda-2.0.6 test/rails_root/app/controllers/posts_controller.rb
technicalpickles-shoulda-2.0.1 test/rails_root/app/controllers/posts_controller.rb
technicalpickles-shoulda-2.0.2 test/rails_root/app/controllers/posts_controller.rb