我想让显示视图页面在Ruby on Rails中使用Grape API

问题描述

我的开发环境是Ruby2.6.5 / Rails 5.2.4

然后...我尝试第一次在rails中使用grape api!

我看到了葡萄api教程和... rake grape:routes命令行输入看到那个屏幕

Grape routes screenshot

比我尝试输入路由的网址,但找不到此屏幕的路由

Error screenshot

我要在访问api路由时显示-如何显示视图文件

#app/api/rails_study/v1/question.rb

module Railsstudy
  module V1
class Question < Grape::API
  version 'v1',using: :path
  format :json
  prefix :api
    
  #여기안에 CRUD 모두 입력
    
  #index action
  resource :questions do
    desc 'Return list of questions'
      
    get do
      question = Question.all
      present question
    end
   end
    
  #show action
  desc 'Return a specific question'
  route_param :id do
    get do
      question = Question.find(params[:id])
      present question
    end
  end

  #update action
  desc 'Update a specific question'
  route_param :id do
    put do
      Question.find(params[:id]).update({ rating:params[:rating] })
    end
  end

  #destroy action
  desc 'Delete a specific question'
  route_param :id do
    delete do
      question = Question.find(params[:id])
      question.destroy
    end
  end

    
  #create action
  desc 'create a new question'
  params do
    requires :name,type: String
    requires :singer,type: String
    requires :rating,type: Float
  end
  post do
    Question.create!({ name:params[:name],singer:params[:singer],rating:params[:rating]
                })
     end
    end
  end
end

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)