【发布时间】:2016-06-05 07:33:46
【问题描述】:
Rails 5.0.0.rc1
Ruby 2.2.5 (can update to latest)
我想这是可能的。 I'm making a get request that when a field is selected then the user presses the next button, it goes to another page and that page's url looks like:
http://localhost:3000/food/r/new?utf8=%E2%9C%93&id=2&food=Apple&commit=Next
对我来说,这看起来很难看。是不是这样更好看:
http://localhost:3000/food/r/new/<some_random_short_string/<name-of-page>
我想some_random_short_string 会是一个哈希,然后在控制器中会有类似的东西:
hash = params[:some_random_short_string]
hash[:food] #=> "Apple"
etc...
不知道该怎么做。请大家指点一下?
【问题讨论】:
-
也许friendly_id gem 可以提供帮助?
-
@seph 不是。我最终可能会在 url 中包含许多字段名称。
-
散列(使用 MD5 或 SHA1)是单向的。您对原始数据进行哈希处理,但永远无法取回它们。
-
@Aetherus 我想通了,谢谢。为此找到了一个简单的方法。我忘记了获取和发布之间的区别;)
标签: ruby-on-rails ruby