Class: Caboose::PostsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Caboose::PostsController
- Defined in:
- app/controllers/caboose/posts_controller.rb
Instance Method Summary collapse
-
#admin_add ⇒ Object
POST /admin/posts.
-
#admin_add_to_category ⇒ Object
PUT /admin/posts/:id/add-to-category.
-
#admin_delete ⇒ Object
DELETE /admin/posts/:id.
-
#admin_delete_form ⇒ Object
GET /admin/posts/:id/delete.
-
#admin_edit_categories ⇒ Object
GET /admin/posts/:id/categories.
-
#admin_edit_content ⇒ Object
GET /admin/posts/:id/content.
-
#admin_edit_general ⇒ Object
GET /admin/posts/:id/edit.
-
#admin_index ⇒ Object
GET /admin/posts.
-
#admin_new ⇒ Object
GET /admin/posts/new.
-
#admin_remove_from_category ⇒ Object
PUT /admin/posts/:id/remove-from-category.
-
#admin_update ⇒ Object
POST /admin/posts/:id.
-
#admin_update_image ⇒ Object
POST /admin/posts/:id/image.
-
#detail ⇒ Object
GET /posts/:id.
-
#index ⇒ Object
GET /posts.
Methods inherited from ApplicationController
#before_action, #before_before_action, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in
Instance Method Details
#admin_add ⇒ Object
POST /admin/posts
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/caboose/posts_controller.rb', line 108 def admin_add return if !user_is_allowed('posts', 'add') resp = Caboose::StdClass.new({ 'error' => nil, 'redirect' => nil }) post = Post.new post.title = params[:title] post.published = false if post.title == nil || post.title.length == 0 resp.error = 'A title is required.' else post.save resp.redirect = "/admin/posts/#{post.id}/edit" end render :json => resp end |
#admin_add_to_category ⇒ Object
PUT /admin/posts/:id/add-to-category
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'app/controllers/caboose/posts_controller.rb', line 131 def admin_add_to_category return if !user_is_allowed('posts', 'edit') post_id = params[:id] cat_id = params[:post_category_id] if !PostCategoryMembership.exists?(:post_id => post_id, :post_category_id => cat_id) PostCategoryMembership.create(:post_id => post_id, :post_category_id => cat_id) end render :json => true end |
#admin_delete ⇒ Object
DELETE /admin/posts/:id
166 167 168 169 170 171 172 173 174 |
# File 'app/controllers/caboose/posts_controller.rb', line 166 def admin_delete return if !user_is_allowed('posts', 'edit') post_id = params[:id] PostCategoryMembership.where(:post_id => post_id).destroy_all Post.where(:id => post_id).destroy_all render :json => { 'redirect' => '/admin/posts' } end |
#admin_delete_form ⇒ Object
GET /admin/posts/:id/delete
159 160 161 162 163 |
# File 'app/controllers/caboose/posts_controller.rb', line 159 def admin_delete_form return if !user_is_allowed('posts', 'delete') @post = Post.find(params[:id]) render :layout => 'caboose/admin' end |
#admin_edit_categories ⇒ Object
GET /admin/posts/:id/categories
55 56 57 58 59 60 |
# File 'app/controllers/caboose/posts_controller.rb', line 55 def admin_edit_categories return if !user_is_allowed('posts', 'edit') @post = Post.find(params[:id]) @categories = PostCategory.reorder(:name).all render :layout => 'caboose/admin' end |
#admin_edit_content ⇒ Object
GET /admin/posts/:id/content
48 49 50 51 52 |
# File 'app/controllers/caboose/posts_controller.rb', line 48 def admin_edit_content return if !user_is_allowed('posts', 'edit') @post = Post.find(params[:id]) render :layout => 'caboose/admin' end |
#admin_edit_general ⇒ Object
GET /admin/posts/:id/edit
41 42 43 44 45 |
# File 'app/controllers/caboose/posts_controller.rb', line 41 def admin_edit_general return if !user_is_allowed('posts', 'edit') @post = Post.find(params[:id]) render :layout => 'caboose/admin' end |
#admin_index ⇒ Object
GET /admin/posts
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/caboose/posts_controller.rb', line 25 def admin_index return if !user_is_allowed('posts', 'view') @gen = Caboose::PageBarGenerator.new(params, { 'name' => '' },{ 'model' => 'Caboose::Post', 'sort' => 'created_at DESC', 'desc' => false, 'base_url' => '/admin/posts' }) @posts = @gen.items render :layout => 'caboose/admin' end |
#admin_new ⇒ Object
GET /admin/posts/new
101 102 103 104 105 |
# File 'app/controllers/caboose/posts_controller.rb', line 101 def admin_new return if !user_is_allowed('posts', 'new') @new_post = Post.new render :layout => 'caboose/admin' end |
#admin_remove_from_category ⇒ Object
PUT /admin/posts/:id/remove-from-category
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/controllers/caboose/posts_controller.rb', line 145 def admin_remove_from_category return if !user_is_allowed('posts', 'edit') post_id = params[:id] cat_id = params[:post_category_id] if PostCategoryMembership.exists?(:post_id => post_id, :post_category_id => cat_id) PostCategoryMembership.where(:post_id => post_id, :post_category_id => cat_id).destroy_all end render :json => true end |
#admin_update ⇒ Object
POST /admin/posts/:id
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/caboose/posts_controller.rb', line 63 def admin_update #Caboose.log(params) return if !user_is_allowed('posts', 'edit') resp = Caboose::StdClass.new({'attributes' => {}}) post = Post.find(params[:id]) save = true params.each do |name, value| case name when 'category_id' then post.category_id = value when 'title' then post.title = value when 'body' then post.body = value when 'published' then post.published = value.to_i == 1 when 'created_at' then post.created_at = DateTime.parse(value) end end resp.success = save && post.save if params[:image] resp.attributes['image'] = { 'value' => post.image.url(:thumb) } end render :json => resp end |
#admin_update_image ⇒ Object
POST /admin/posts/:id/image
88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/caboose/posts_controller.rb', line 88 def admin_update_image return if !user_is_allowed('posts', 'edit') resp = Caboose::StdClass.new post = Post.find(params[:id]) post.image = params[:image] resp.success = post.save resp.attributes = { 'image' => { 'value' => post.image.url(:thumb) }} render :text => resp.to_json end |
#detail ⇒ Object
GET /posts/:id
12 13 14 15 16 17 18 |
# File 'app/controllers/caboose/posts_controller.rb', line 12 def detail @post = Post.find_by_id(params[:id]) unless @post.present? flash[:notice] = 'The posts post you tried to access does not exist.' redirect_to action: :index end end |
#index ⇒ Object
GET /posts
7 8 9 |
# File 'app/controllers/caboose/posts_controller.rb', line 7 def index @posts = Post.where(:published => true).limit(5).order('created_at DESC') end |