0

我有一个 Rails 应用程序,它有一个名为模型的模型,它Product有两个名为product_name,的字段product_price。设计 gem 也用于身份验证。电子邮件和密码是登录的两个凭据。

如何使用REST创建产品?URL 结构是什么?

谢谢

我的网络应用程序功能齐全。我想创建一个 API 来从另一个网站访问这个应用程序。我想提供一个 URL,一个人将在其中单击并在我的站点中创建产品。

前提是该人已注册。所以我的主要问题是,如何通过 URL 将身份验证、发布、产品名称、产品价格等请求发送到创建操作。

4

1 回答 1

0
# Models:

class User
  has_many :products
end
class Product
  belongs_to :user
end

# Routes:

resources :user  # Access stuff individually
resources :product
resources :user do # or nested, e.g. user/:id/product/:id   
  resources :product
end

# type rake rake routes to see the paths you can use. 

# Forms can use, e.g. for product for a given user 
<%= form_for ([@user,@product]) do |p| %>

# Links can be of the form 
<%= link_to 'Add User', new_user_path %>
于 2012-09-20T11:07:41.670 回答