Class: Helios::Press::Admin::PostsController
- Inherits:
-
BaseController
- Object
- ApplicationController
- BaseController
- Helios::Press::Admin::PostsController
- Defined in:
- app/controllers/helios/press/admin/posts_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/helios/press/admin/posts_controller.rb', line 22 def create @post = Post.new(post_params) if @post.save redirect_to helios_press.edit_admin_post_path(@post), notice: "Post was successfully created." else render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
51 52 53 54 |
# File 'app/controllers/helios/press/admin/posts_controller.rb', line 51 def destroy @post.destroy redirect_to helios_press.admin_posts_path, notice: "Post was successfully deleted." end |
#edit ⇒ Object
32 33 |
# File 'app/controllers/helios/press/admin/posts_controller.rb', line 32 def edit end |
#index ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'app/controllers/helios/press/admin/posts_controller.rb', line 7 def index @posts = Post.reverse_sorted if params[:search].present? search_term = "%#{params[:search]}%" @posts = @posts.where("name ILIKE ? OR keywords ILIKE ?", search_term, search_term) end @posts = @posts.order(created_at: :desc) end |
#new ⇒ Object
18 19 20 |
# File 'app/controllers/helios/press/admin/posts_controller.rb', line 18 def new @post = Post.new end |
#update ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/helios/press/admin/posts_controller.rb', line 35 def update if params[:publish].present? update_params = post_params.merge(published: true) = "Post was successfully published." else update_params = post_params = "Post was successfully updated." end if @post.update(update_params) redirect_to helios_press.edit_admin_post_path(@post), notice: else render :edit, status: :unprocessable_entity end end |