新手问题 如何通过发送 JSON 数据到 create 动作?

zix · August 01, 2016 · Last by rikiwong replied at August 01, 2016 · 1669 hits

如题。

# POST /tickets
  # POST /tickets.json
  def create
    @ticket = Ticket.new(ticket_params)

    respond_to do |format|
      if @ticket.save
        format.html { redirect_to @ticket, notice: 'Ticket was successfully created.' }
        format.json { render :show, status: :created, location: @ticket }
      else
        format.html { render :new }
        format.json { render json: @ticket.errors, status: :unprocessable_entity }
      end
    end
  end

用骨架建造的动作中,似乎 POST 一个 tickets.json 即可创建一个模型。 是否应该用 http 协议,向根目录发送一个 ticket.json? 完整的内容应该是怎么样的呢?

用 curl 或者 postman 或者 js 的 ajax 向 youwebsitename.com/tickets 发送 post 请求

You need to Sign in before reply, if you don't have an account, please Sign up first.