在我的Ruby on Rails应用程序中,自行车租赁公司可以管理所有自行车(预订,付款等。)>
目标
我想为自行车租赁公司提供在自己的网站上执行预订表格的选项,这样他们就可以让客户为特定的自行车创建预订。
此预订表格将把可用的自行车从我的Rails应用程序带到他们的网站,然后将新的预订数据发送回Rails应用程序。
问题
如何将商店的网站链接到应用程序中的特定Shop
。从而,确保特定的网站确实应该能够获取属于Shop
的信息。
[代码
] >>型号
class Shop < ApplicationRecord has_many :bike_categories, dependent: :destroy has_many :bikes, through: :bike_categories has_many :user_shops, dependent: :destroy has_many :users, through: :user_shops has_many :reservations, dependent: :destroy accepts_nested_attributes_for :users, allow_destroy: true, reject_if: ->(attrs) { attrs['email'].blank? || attrs['role'].blank?} end class User < ApplicationRecord has_many :user_shops, dependent: :destroy has_many :shops, through: :user_shops accepts_nested_attributes_for :user_shops enum role: [:owner, :admin, :employee, :accountant, :demo, :app_owner] end class Reservation < ApplicationRecord belongs_to :shop belongs_to :bike end
controllers / api / v1 / reservations_controller
def create # How to know/specify which shop? @shop = Shop.new(shop_params) authorize @shop if @shop.save render :show, status: :created else render_error end end
在我的Ruby on Rails应用程序中,自行车租赁公司可以管理其所有自行车(预订,付款等)。目标我想为自行车租赁公司提供在...
这是您的nested resource的教科书示例。在REST中,嵌套资源嵌套在另一个资源的路径中:
/authors/1/books
/countries/uk/cities
/blogs/1/posts/2