Class: OCms::PostsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- OCms::PostsController
- Defined in:
- app/controllers/o_cms/posts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/o_cms/posts_controller.rb', line 19 def create @post = Post.new(post_params) if @post.save flash[:notice] = "Post was saved successfully." redirect_to edit_post_path(@post) else flash.now[:alert] = "Error creating post. Please try again." render :new end end |
#destroy ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/o_cms/posts_controller.rb', line 49 def destroy @post = Post.find(params[:id]) if @post.destroy flash[:notice] = "\"#{@post.title}\" was deleted successfully." redirect_to action: :index else flash.now[:alert] = "There was an error deleting the post." render :show end end |
#edit ⇒ Object
31 32 33 34 |
# File 'app/controllers/o_cms/posts_controller.rb', line 31 def edit @post = Post.find(params[:id]) @categories = Category.all end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/o_cms/posts_controller.rb', line 6 def index @posts = Post.all end |
#new ⇒ Object
14 15 16 17 |
# File 'app/controllers/o_cms/posts_controller.rb', line 14 def new @post = Post.new @categories = Category.all end |
#show ⇒ Object
10 11 12 |
# File 'app/controllers/o_cms/posts_controller.rb', line 10 def show @post = Post.find(params[:id]) end |
#update ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/o_cms/posts_controller.rb', line 36 def update @post = Post.find(params[:id]) @post.assign_attributes(post_params) if @post.save flash[:notice] = "Post was updated successfully." redirect_to edit_post_path(@post) else flash.now[:alert] = "Error saving post. Please try again." render :edit end end |