【问题标题】:Ruby On Rails --apiRuby On Rails --api
【发布时间】:2015-12-03 19:33:17
【问题描述】:

我使用 --api 参数创建新的 Rails 应用程序,如手动 http://edgeguides.rubyonrails.org/api_app.html

rails new app2 --api

我使用的脚手架

bin/rails generate scaffold People first_name:string last_name:string age:integer

Rails 生成的控制器不仅包含 json 结果的操作,而且不需要“新建”和“编辑”操作,以及 html 渲染
它还会生成

  create      app/views/people
  create      app/views/people/index.html.erb
  create      app/views/people/edit.html.erb
  create      app/views/people/show.html.erb
  create      app/views/people/new.html.erb
  create      app/views/people/_form.html.erb

我不需要,因为我只需要 API
为什么?
我想收到结果,就像我使用 rails-api gem
Rails 的版本是 4.2.5

【问题讨论】:

    标签: ruby-on-rails api rest


    【解决方案1】:

    如果只想生成modelcontroller,可以使用:

    bin/rails generate resource People first_name:string last_name:string age:integer
    

    【讨论】:

    • 我需要像 "rails-api" gem 中的脚手架,带有 CRUD 操作,但仅适用于 json 上的 REST API。没有 html 模板和 html 操作
    【解决方案2】:

    我找到了答案。 "--api" 命令仅适用于 5.0 Rails

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-24
      • 2017-06-16
      • 2017-01-16
      • 2011-07-05
      • 1970-01-01
      • 2012-08-25
      • 2011-04-01
      相关资源
      最近更新 更多