Class: Parlez::Admin::PostsController
- Inherits:
-
BaseController
- Object
- BaseController
- Parlez::Admin::PostsController
- Defined in:
- app/controllers/parlez/admin/posts_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/parlez/admin/posts_controller.rb', line 13 def create @post = Parlez::Post.create!(params[:parlez_post]) flash[:notice] = 'Post created!' redirect_to :action => :index rescue ActiveRecord::RecordInvalid => e @post = e.record flash[:error] = 'Please correct the errors below.' render :action => :new end |
#destroy ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/parlez/admin/posts_controller.rb', line 41 def destroy @post = Parlez::Post.find(params[:id]) @post.destroy flash[:notice] = 'Post deleted.' redirect_to :action => :index rescue ActiveRecord::RecordNotFound flash[:error] = 'Post not found!' redirect_to :action => :index end |
#edit ⇒ Object
23 24 25 |
# File 'app/controllers/parlez/admin/posts_controller.rb', line 23 def edit @post = Parlez::Post.find(params[:id]) end |
#index ⇒ Object
5 6 7 |
# File 'app/controllers/parlez/admin/posts_controller.rb', line 5 def index @posts = Parlez::Post.order('published_at DESC').all end |
#new ⇒ Object
9 10 11 |
# File 'app/controllers/parlez/admin/posts_controller.rb', line 9 def new @post = Parlez::Post.new end |
#update ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/parlez/admin/posts_controller.rb', line 27 def update @post = Parlez::Post.find(params[:id]) @post.update_attributes!(params[:parlez_post]) flash[:notice] = 'Post saved!' redirect_to :action => :index rescue ActiveRecord::RecordInvalid => e @post = e.record flash[:error] = 'Please correct the errors below.' render :action => :edit rescue ActiveRecord::RecordNotFound flash[:error] = 'Post not found!' redirect_to :action => :index end |