Class: HomesteadingPublisher::PostsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- HomesteadingPublisher::PostsController
- Defined in:
- app/controllers/homesteading_publisher/posts_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
require auth.
-
#destroy ⇒ Object
require auth.
-
#edit ⇒ Object
require auth.
- #index ⇒ Object
-
#new ⇒ Object
require auth.
- #show ⇒ Object
-
#update ⇒ Object
require auth.
Instance Method Details
#create ⇒ Object
require auth
31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/homesteading_publisher/posts_controller.rb', line 31 def create @post = Post.new(post_params) if @post.save headers["Location"] = post_url(@post.params) redirect_to post_url(@post.params), notice: "Post was successfully created." else render action: "new" end end |
#destroy ⇒ Object
require auth
51 52 53 54 |
# File 'app/controllers/homesteading_publisher/posts_controller.rb', line 51 def destroy @post.destroy redirect_to root_url end |
#edit ⇒ Object
require auth
26 27 28 |
# File 'app/controllers/homesteading_publisher/posts_controller.rb', line 26 def edit @page_title = "Editing Post - #{@post.name}" end |
#index ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'app/controllers/homesteading_publisher/posts_controller.rb', line 5 def index @page_title = "Posts" @posts = Post.paginate(per_page: 5, page: params[:page]) @posts = @posts.where(year: params[:year]) if params[:year] @posts = @posts.where(month: params[:month]) if params[:month] @posts = @posts.where(day: params[:day]) if params[:day] end |
#new ⇒ Object
require auth
20 21 22 23 |
# File 'app/controllers/homesteading_publisher/posts_controller.rb', line 20 def new @page_title = "New Post" @post = Post.new end |
#show ⇒ Object
15 16 17 |
# File 'app/controllers/homesteading_publisher/posts_controller.rb', line 15 def show @page_title = @post.name end |
#update ⇒ Object
require auth
42 43 44 45 46 47 48 |
# File 'app/controllers/homesteading_publisher/posts_controller.rb', line 42 def update if @post.update(post_params) redirect_to post_url(@post.params), notice: "Post was successfully updated." else render action: "edit" end end |