Sha256: 6dcd1f101a5e3f7bd5e74b3ec076cbabe0646c866faf204838fd004c8280edf1

Contents?: true

Size: 476 Bytes

Versions: 9

Compression:

Stored size: 476 Bytes

Contents

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

    params do
      param :title, presence: true
    end

    def call(params)
      self.format = :json
      halt 400, JSON.dump(errors: ["Required param `title` is not specified"]) unless params.valid?

      @post = Octodmin::Post.create(title: params[:title])
      halt 400, JSON.dump(errors: ["Post with specified `title` already exists"]) unless @post
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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