Reputation: 20263
I'm sure this is a bone-headed question, so apologies in advance. I want to use a string with my redirect_to, like this:
class AppStoreController < ApplicationController
def get_app
.
.
.
redirect_path_string = "address_book_path"
redirect_to redirect_path_string
end
end
(The redirect_path_string will be constructed using available variables in the controller, but I wanted to abstract out that detail for this question.)
When I do this, I get "The connection was reset" in my browser.
Any thoughts?
Upvotes: 2
Views: 2915
Reputation: 2941
You need to supply a fully qualified URL in order to use a string against redirect_to. Rails utilize a convention to generate a URL from *_path, in this case 'address_book_path'. The following is some examples of what you can do with redirect_to. For more info, go 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
Upvotes: 7