如何使用redirect_to的字符串?

jvi*_*ian 2 redirect ruby-on-rails

我确信这是一个愚蠢的问题,所以请提前道歉.我想在我的redirect_to中使用一个字符串,如下所示:

class AppStoreController < ApplicationController

  def get_app
    .
    .
    .
    redirect_path_string = "address_book_path"
    redirect_to redirect_path_string
  end

end
Run Code Online (Sandbox Code Playgroud)

(redirect_path_string将使用控制器中的可用变量构造,但我想抽象出这个问题的详细信息.)

当我这样做时,我的浏览器中显示"连接已重置".

有什么想法吗?

Yos*_*Kim 7

您需要提供完全限定的URL才能对redirect_to使用字符串.Rails利用约定从*_path生成URL,在本例中为'address_book_path'.以下是使用redirect_to可以执行的操作的一些示例.有关更多信息,请访问http://apidock.com/rails/ActionController/Base/redirect_to

redirect_to :action => "show", :id => 5
redirect_to post
redirect_to "http://www.rubyonrails.org"
redirect_to "/images/screenshot.jpg"
redirect_to articles_url
redirect_to :back
Run Code Online (Sandbox Code Playgroud)