Sha256: 5e1c5f33bac365336e8cb28c291176578db6b8b6cdb9e69651478c2cd237a0fd

Contents?: true

Size: 658 Bytes

Versions: 9

Compression:

Stored size: 658 Bytes

Contents

module Octodmin::Controllers::Posts
  class Update
    include Octodmin::Action
    expose :post

    params do
      param :layout, presence: true
      param :title, presence: true
      param :slug, presence: true
      param :date, presence: true
      param :content, presence: true
    end

    def call(params)
      self.format = :json

      @post = Octodmin::Post.find(params.env["router.params"][:id])
      halt 400, JSON.dump(errors: ["Could not find post"]) unless @post
      halt 400, JSON.dump(errors: ["Required params are not specified"]) unless params.valid?
      @post.update(params.env["rack.request.form_hash"].dup)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
octodmin-0.3.5 app/controllers/posts/update.rb
octodmin-0.3.4 app/controllers/posts/update.rb
octodmin-0.3.3 app/controllers/posts/update.rb
octodmin-0.3.2 app/controllers/posts/update.rb
octodmin-0.3.1 app/controllers/posts/update.rb
octodmin-0.3.0 app/controllers/posts/update.rb
octodmin-0.2.1 app/controllers/posts/update.rb
octodmin-0.2.0 app/controllers/posts/update.rb
octodmin-0.1.0 app/controllers/posts/update.rb