【问题标题】:Rails- add hash to redirect_toRails-将哈希添加到redirect_to
【发布时间】:2010-11-23 12:16:52
【问题描述】:

我需要指定一个散列来添加到redirect_to。我该怎么做?

这就是我的redirect_to 的形成方式:

 redirect_to :action => 'show', :id => @consultant.id

我需要访问 example.com/consultant/#some_hash

谢谢!

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3


    【解决方案1】:

    试试redirect_to your_current_options, :anchor => 'fragment_identifier'

    http://api.rubyonrails.org/classes/ActionDispatch/Routing/UrlFor.html#method-i-url_for

    【讨论】:

      【解决方案2】:

      我遇到了类似的问题。我试过这个:

      redirect_to @post, anchor: 'tab_items'
      

      但不能使用 rails 4.2.6。但是,如果我更改为以下内容,并且现在可以正常工作:

      redirect_to post_path(@post, anchor: 'tab_items')
      

      【讨论】:

      • 没错。 anchor 属性属于 path 和 url 助手,而不是 redirect_to
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-03
      • 1970-01-01
      • 2020-12-08
      • 2011-07-28
      • 2016-09-03
      • 1970-01-01
      相关资源
      最近更新 更多