我必须使用葡萄link创建一个休息api。在其余的api我不想使用Rails gem它可以使用简单的gem创建。
如果我必须创建用户模型然后使用此命令,如何使用rake in rails创建模型或数据库对象
rails generate model User name:string email:string
当我只使用Rack时,有什么选择。请提供一些有用的链接,仅使用rails创建数据库应用程序。我必须使用postgresql !!
答案 0 :(得分:0)
Grape非常适合REST API。它不会为您构建模型。
您使用的是数据库,例如sqlite,mysql,postgres等吗?
我非常喜欢数据库连接的“续集”宝石。
这是续集页面中的好消息:
require "rubygems"
require "sequel"
# connect to an in-memory database
DB = Sequel.sqlite
# create an items table
DB.create_table :items do
primary_key :id
String :name
Float :price
end
# create a dataset from the items table
items = DB[:items]
# populate the table
items.insert(:name => 'abc', :price => 100)
items.insert(:name => 'def', :price => 120)
items.insert(:name => 'ghi', :price => 150)
# print out the number of records
puts "Item count: #{items.count}"
# print out the average price
puts "The average price is: #{items.avg(:price)}"
有关续集的更多信息,请参阅http://sequel.rubyforge.org/