Class: Blogr::PostsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Blogr::PostsController
- Defined in:
- app/controllers/blogr/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
35 36 37 38 39 40 41 42 |
# File 'app/controllers/blogr/posts_controller.rb', line 35 def create @post = current_blogr_user.posts.build(post_params) if @post.save redirect_to @post, notice: "Post was successfully created" else render action: "new" end end |
#destroy ⇒ Object
53 54 55 56 |
# File 'app/controllers/blogr/posts_controller.rb', line 53 def destroy @post.destroy redirect_to posts_url, notice: "Post was successfully destroyed" end |
#edit ⇒ Object
28 29 30 31 32 33 |
# File 'app/controllers/blogr/posts_controller.rb', line 28 def edit if params[:delete_image] Image.find(params[:delete_image]).try :destroy end @title = "Editing '#{@post.title}'" end |
#index ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/blogr/posts_controller.rb', line 8 def index pub = params[:published] == "false" ? false : true @posts = Post.order(published_at: :desc).where(published: pub) @title = "Posts" if pub @subtitle = "Showing Published Posts" else @subtitle = "Showing Draft Posts" end end |
#new ⇒ Object
23 24 25 26 |
# File 'app/controllers/blogr/posts_controller.rb', line 23 def new @post = Post.new @title = "New Post" end |
#show ⇒ Object
19 20 21 |
# File 'app/controllers/blogr/posts_controller.rb', line 19 def show @title = @post.title end |
#update ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'app/controllers/blogr/posts_controller.rb', line 44 def update if @post.update(post_params) redirect_to @post, notice: "Post was successfully updated" else render action: "edit" end end |