該賞金過期4天。回答這個問題有資格獲得 50聲望獎勵。 Samuel Da Costa正在尋找規范的答案。
例如,我想在請求中傳遞給資源
# Go to payment link
<%= link_to 'Payment', checkout_path(pricing: amount.id) %>
當我轉到付款鏈接時,網址路徑是下一個:
http://localhost:3000/checkout?pricing=amount_2aHUHuhdn23jnSJd
我想隱藏查詢字串“pricing=amount_2aHUHuhdn23jnSJd”而不必使用任何 gem
更新問題 31/12
這個請求是 Get 型別的,因為我需要向用戶顯示不同的價格,這就是引數傳遞的原因(定價:amount.id)
<%= link_to 'Payment', checkout_path(pricing: amount.id) %>
get 'checkout', to: 'subscriptions#checkout'
我很感激你的時間和你的一粒沙子
uj5u.com熱心網友回復:
如果沒有看到您的 routes.rb 檔案,我不太確定您的意思。正如@Deepak Kumar 提到的,要從您的 url 隱藏查詢,您應該使用 POST 請求。看看這個指南。您可以在下方添加
post 'payment', to: 'checkout#payment'
在你的 routes.rb 中。這將要求Payment您采取行動CheckoutsController
uj5u.com熱心網友回復:
當該值敏感時,隱藏該值并不能真正解決問題。相反,我建議加密 URL 中的值或使用另一個非敏感值。
- 值加密
您可以MessageEncryptor在將值傳遞給 URL 之前使用 Rails對其進行加密,并稍后在控制器中再次對其進行解密。
# in app/models/url_encrypter.rb
module URLEncrypter
ENCRYPTER = ActiveRecord::MessageEncryptor.new(
Rails.application.secrets.secret_key_base
)
def encrypt(value)
ENCRYPTOR.encrypt_and_sign(value, purpose: :url)
end
def decrypt(value)
ENCRYPTOR.decrypt_and_verify(value, purpose: :url)
end
end
# when building the URL
<%= link_to 'Payment', checkout_path(pricing: URLEncrypter.encyrpt(amount.id)) %>
# when reading the param in the controller
pricing = URLEncrypter.decyrpt(params[:pricing])
amount = Amount.find(pricing)
- 有第二個不敏感的唯一識別符號
在這里,您向資料庫表中添加了第二個唯一識別符號,例如,uuid您可以在before_save回呼中自動填充一個名為的列self.uuid = SecureRandom.uuid
然后你可以使用它的值而不是id這樣的:
# when building the URL
<%= link_to 'Payment', checkout_path(pricing: amount.uuid) %>
# when reading the param in the controller
amount = Amount.find_by(uuid: params[:pricing])
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/403196.html
標籤:
