我正在尝试
自定义我的节目路线…我不希望
用户能够通过以下方式查看项目:id …
我有一个销售模型,展示路线是:
@H_
301_4@sale GET /sales/:id(.:format) sales#show
但是,我不希望用户能够通过id查看销售,相反,我希望它是:
@H_
301_4@sale GET /sales/:guid(.:format) sales#show
guid是我在创建对象时生成的uuid:
@H_
301_4@def populate_guid
self.guid = SecureRandom.uuid()
end
在config / routes.rb中
@H_
301_4@get '/sales/:guid',to: 'sales#show'
或者如果您使用rails 4,您可以:
@H_
301_4@resources :sales,param: :guid
在控制器中
@H_
301_4@def show
@sale = Sale.find(params[:guid])
end