railsのAPIモードでの開発しています。
Postmanを使ってPOSTリクエストして、データを作成したいのですが、
リクエストを送信できません。
どなたか原因がわかる方おられますでしょうか。
###開発環境
~ % rails -v
Rails 5.2.6
~ % bundle -v
Bundler version 1.17.2
###各ファイル
ruby
1#20210917122447create_users.rb 2 3class CreateUsers < ActiveRecord::Migration[5.2] 4 def change 5 create_table :users do |t| 6 t.string :name 7 t.string :user_id 8 t.string :email 9 t.string :password 10 11 t.timestamps 12 end 13 end 14end
ruby
1#schema.rb 2 3# This file is auto-generated from the current state of the database. Instead 4# of editing this file, please use the migrations feature of Active Record to 5# incrementally modify your database, and then regenerate this schema definition. 6# 7# Note that this schema.rb definition is the authoritative source for your 8# database schema. If you need to create the application database on another 9# system, you should be using db:schema:load, not running all the migrations 10# from scratch. The latter is a flawed and unsustainable approach (the more migrations 11# you'll amass, the slower it'll run and the greater likelihood for issues). 12# 13# It's strongly recommended that you check this file into your version control system. 14ActiveRecord::Schema.define(version: 2021_09_19_122338) do 15 16 create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| 17 t.string "name" 18 t.string "user_id" 19 t.string "email" 20 t.string "password" 21 t.datetime "created_at", null: false 22 t.datetime "updated_at", null: false 23 end 24 25end
ruby
1#routes.rb 2 3Rails.application.routes.draw do 4 # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 5 namespace :api do 6 namespace :v1 do 7 resources :hello, only: [:index] 8 resources :users, only: [:create, :show] 9 10 end 11 end 12end 13
ruby
1#users_controller.rb 2 3module Api 4 module V1 5 class UsersController < ApplicationController 6 def create 7 user = User.create(user_params) 8 9 if user.save 10 render json: { status: 'SUCCESS', data: user} 11 else 12 render json: { status: 'ERROR', data: user.errors } 13 end 14 end 15 16 private 17 18 def user_params 19 params.require(:user).permit(:name, :user_id, :email, :password) 20 end 21 end 22 end 23end 24
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。