class Miniblog::Admin::PostsController
Public Instance Methods
create()
click to toggle source
# File app/controllers/miniblog/admin/posts_controller.rb, line 18 def create @post = Post.new(post_params) @post.state = :drafted @post.author = current_user @post.regenerate_permalink if @post.save after_post_is_saved redirect_to miniblog.edit_admin_post_path(@post), notice: "Post created succesfully" else render action: :new end end
destroy()
click to toggle source
# File app/controllers/miniblog/admin/posts_controller.rb, line 31 def destroy @post.destroy redirect_to miniblog.admin_posts_path end
edit()
click to toggle source
# File app/controllers/miniblog/admin/posts_controller.rb, line 40 def edit end
index()
click to toggle source
# File app/controllers/miniblog/admin/posts_controller.rb, line 12 def index @state = params[:state] @posts = Post.for_admin_index @posts = @posts.with_state(@state) if @state end
new()
click to toggle source
# File app/controllers/miniblog/admin/posts_controller.rb, line 6 def new @post = Post.new @post.state = :drafted @post.author = current_user end
show()
click to toggle source
# File app/controllers/miniblog/admin/posts_controller.rb, line 36 def show @post = Post.includes(:assets).find(params[:id]) end
update()
click to toggle source
# File app/controllers/miniblog/admin/posts_controller.rb, line 43 def update handle_asset if @post.update_attributes(post_params) if @post.allowed_to_update_permalink? @post.regenerate_permalink @post.save! end after_post_is_saved flash[:notice] = "Post updated succesfully" end render action: :edit end
Private Instance Methods
handle_asset()
click to toggle source
# File app/controllers/miniblog/admin/posts_controller.rb, line 68 def handle_asset if asset_params = post_params.delete(:asset) @asset = @post.assets.build(asset) @asset.attachment = asset_params[:attachment] end end
load_post()
click to toggle source
# File app/controllers/miniblog/admin/posts_controller.rb, line 58 def load_post @post = Post.scoped_for(current_user).find(params[:id]) end
post_params()
click to toggle source
# File app/controllers/miniblog/admin/posts_controller.rb, line 62 def post_params @params ||= params.require(:post). permit(:title, :body, :updated_by, :ready_for_review, :transition, { asset: [ :attachment ]}) end