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
29 30 31 32 33 34 35 36 |
# File 'app/controllers/blogr/posts_controller.rb', line 29 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
47 48 49 50 |
# File 'app/controllers/blogr/posts_controller.rb', line 47 def destroy @post.destroy redirect_to posts_url, notice: "Post was successfully destroyed" end |
#edit ⇒ Object
22 23 24 25 26 27 |
# File 'app/controllers/blogr/posts_controller.rb', line 22 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 |
# File 'app/controllers/blogr/posts_controller.rb', line 8 def index @posts = Post.order(published_at: :desc) @title = "Posts" end |
#new ⇒ Object
17 18 19 20 |
# File 'app/controllers/blogr/posts_controller.rb', line 17 def new @post = Post.new @title = "New Post" end |
#show ⇒ Object
13 14 15 |
# File 'app/controllers/blogr/posts_controller.rb', line 13 def show @title = @post.title end |
#update ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'app/controllers/blogr/posts_controller.rb', line 38 def update if @post.update(post_params) redirect_to @post, notice: "Post was successfully updated" else render action: "edit" end end |