Class: Blogaze::Controllers::Admin::Posts
- Inherits:
-
Controller
- Object
- Ramaze::Controller
- Controller
- Controller
- Blogaze::Controllers::Admin::Posts
- Defined in:
- lib/blogaze/controllers/admin/posts.rb
Instance Method Summary collapse
-
#create ⇒ Object
Create post.
-
#delete(post_id) ⇒ Object
Delete post.
-
#edit(post_id) ⇒ Object
Edit post.
-
#index ⇒ Object
Post listing.
-
#initialize ⇒ Posts
constructor
A new instance of Posts.
-
#new ⇒ Object
New post form.
-
#save(post_id) ⇒ Object
Save post.
Methods inherited from Controller
#get_settings, #title, #view_file
Constructor Details
#initialize ⇒ Posts
Returns a new instance of Posts.
15 16 17 18 19 20 |
# File 'lib/blogaze/controllers/admin/posts.rb', line 15 def initialize super # Set title title "Posts" end |
Instance Method Details
#create ⇒ Object
Create post
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/blogaze/controllers/admin/posts.rb', line 67 def create data = { :title => request[:title], :body => request[:body], :user_id => @userinfo.id, :post_tags => request[:post_tags].is_a?(String) ? request[:post_tags].gsub(', ', ',').split(',') : [] } @post = ::Blogaze::Models::Post.new(data) if @post.valid? @post.save flash[:success] = "Post created successfully" redirect Posts.r('/') else @post. = @post..join(', ') respond(view_file('admin/posts/new')) end end |
#delete(post_id) ⇒ Object
Delete post
128 129 130 131 132 133 134 |
# File 'lib/blogaze/controllers/admin/posts.rb', line 128 def delete(post_id) post = ::Blogaze::Models::Post[post_id] post.delete ::Blogaze::Models::TagsRelationship.where(:object_type => 'post', :object_id => post.id).delete flash[:success] = "Post deleted successfully" redirect Posts.r('/') end |
#edit(post_id) ⇒ Object
Edit post
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/blogaze/controllers/admin/posts.rb', line 91 def edit(post_id) @post = ::Blogaze::Models::Post[post_id] = [] @post..each do |tag| .push tag.name end @post. = .join(', ') respond(view_file('admin/posts/edit')) end |
#index ⇒ Object
Post listing
51 52 53 54 |
# File 'lib/blogaze/controllers/admin/posts.rb', line 51 def index @posts = ::Blogaze::Models::Post.order(:id.desc).all respond(view_file('admin/posts/index')) end |
#new ⇒ Object
New post form
59 60 61 62 |
# File 'lib/blogaze/controllers/admin/posts.rb', line 59 def new @post = ::Blogaze::Models::Post.new respond(view_file('admin/posts/new')) end |
#save(post_id) ⇒ Object
Save post
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/blogaze/controllers/admin/posts.rb', line 108 def save(post_id) @post = ::Blogaze::Models::Post[post_id] @post.title = request[:title] @post.body = request[:body] @post. = request[:post_tags].is_a?(String) ? request[:post_tags].gsub(', ', ',').split(',') : [] if @post.valid? @post.save flash[:success] = "Post saved successfully" redirect Posts.r('/') else respond(view_file('admin/posts/edit')) end end |