Class: Crowdblog::PostsController
- Inherits:
-
Controller
- Object
- ActionController::Base
- Controller
- Crowdblog::PostsController
- Defined in:
- app/controllers/crowdblog/posts_controller.rb
Instance Method Summary collapse
Methods inherited from Controller
Instance Method Details
#create ⇒ Object
14 15 16 17 18 19 20 |
# File 'app/controllers/crowdblog/posts_controller.rb', line 14 def create @post = Post.new(params[:post]) @post. = current_user @post.regenerate_permalink @post.save respond_with @post end |
#destroy ⇒ Object
22 23 24 25 26 |
# File 'app/controllers/crowdblog/posts_controller.rb', line 22 def destroy @post = Post.scoped_for(current_user).find(params[:id]) @post.destroy respond_with @post end |
#index ⇒ Object
6 7 8 9 10 11 12 |
# File 'app/controllers/crowdblog/posts_controller.rb', line 6 def index @posts = Post.scoped_for(current_user).all_posts_json respond_to do |format| format.json { render json: @posts } format.html end end |
#show ⇒ Object
28 29 30 31 32 33 |
# File 'app/controllers/crowdblog/posts_controller.rb', line 28 def show @post = Post.includes(:assets).find(params[:id]) respond_to do |format| format.json { render json: @post.to_json(include: :assets) } end end |
#update ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/crowdblog/posts_controller.rb', line 35 def update @post = Post.scoped_for(current_user).find(params[:id]) @post.update_attributes(params[:post], updated_by: current_user) if @post.allowed_to_update_permalink? @post.regenerate_permalink @post.save! end @post.publish_if_allowed(params[:transition], current_user) if params[:transition] respond_with @post end |