Reputation: 2246
I have this redirection in the middle of my controller so if something isn't there, it will redirect you to a new area of the site if needed. Here is the problem. It is just ignoring the redirect in the code. It looks like this.
if conditions
redirect_to "/new/address"
end
I can't even figure out why it won't redirect, but I know it makes it into the conditional and literally just ignores the redirect. What am I missing here!?
I am using Rails 2 and Ruby 1.8
Upvotes: 0
Views: 48
Reputation: 18037
Don't forget that a redirect_to
or render
call in a Rails action do not terminate the method. Method execution continues to the end before the redirect/render is performed. So if you're looking to terminate execution of the method at that point add a return
statement. The usual pattern is:
redirect_to(<my route>) and return
Upvotes: 1
Reputation: 796
What are you seeing? Is it raising an error? Is there an error message in the console when running "script/server"? For this to work, there should be something to handle the path "new", typically a controller called "NewsController" (plural form) or some rule in the routes.rb
file.
If you are seeking to create a new address, then you may be looking for something like
if conditions
redirect_to new_address_path
end
Upvotes: 1
Reputation: 4436
Did you try to use rails paths instead of a string path there?
Try something like
redirect_to :action => 'new'
if the method is inside this controller, or something like
redirect_to :controller => 'adress', :action => 'new'
To see if the result changes.
Upvotes: 1