Forum: Ruby on Rails issue with redirect_to

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Susanta (Guest)
on 2006-03-13 17:02
Hi all:
I can't make redirect_to to unlock the current iframe using {:TARGET =>
"_top"}.  It always stays in the current frame. I checked the
redirect_to code, it seems the method does not use "target". here is the
source code of redirect_to from ActionController::Base

def redirect_to(options = {}, *parameters_for_method_reference) #:doc:
753:         case options
754:           when %r{^\w+://.*}
755:             raise DoubleRenderError if performed?
756:             logger.info("Redirected to #{options}") unless
logger.nil?
757:             response.redirect(options)
758:             response.redirected_to = options
759:             @performed_redirect = true
760:
761:           when String
762:             redirect_to(request.protocol + request.host_with_port
+ options)
763:
764:           when :back
765:             redirect_to(request.env["HTTP_REFERER"])
766:
767:           else
768:             if parameters_for_method_reference.empty?
769:               redirect_to(url_for(options))
770:               response.redirected_to = options
771:             else
772:               redirect_to(url_for(options,
*parameters_for_method_reference))
773:               response.redirected_to,
response.redirected_to_method_params = options,
parameters_for_method_reference
774:             end
775:         end
776:       end
------------------------------------------------------------------------
' when %r{^\w+://.*} ' does not use 'parameters_for_method_reference'.
Bug ?
I also tried to use response directly as follows:
    response.redirect(params[:url]+' target="_top"')
    response.redirected_to = params[:url]+' target="_top"'
but it didn't work. Is this a know bug ?

thanks in advance for your reply.
regards
Susanta

Here is my sample code:
controller: BlogController
--------------------code-----------------------------------
class BlogController < ApplicationController
  def index
  end

  def otherFrame
    render(:layout => false)
  end

  def show
    redirect_to(params[:url], {:TARGET => "_top"})
  end
end
</BlogController.rb >
layout: blog
blog
<html>
<body>
<iframe src="otherFrame" marginheight=2 marginwidth=2
allowTransparency="true" width=700 height=110>
</iframe>
<%= @content_for_layout %>
</body>
</html>
-------------------------------
views: index.rhtml
--------------------code-----------------------------------
<p>I am in a different frame</p>
-----------------------------
views: otherFrame.rhtml
--------------------code-----------------------------------
<html>
<body>
<p>Locked in a frame?</p>
<%= link_to 'click me', :action => 'show', :url
=>"http://www.rubyonrails.org/" %>
</body>
</html>
------------------------------
Cheltis (Guest)
on 2006-03-13 17:19
You cannot possibly do that with server-side script. The only way would
be to genereate javascript that will redirect browser using target =
_top

Susanta wrote:
> Hi all:
> I can't make redirect_to to unlock the current iframe using {:TARGET =>
> "_top"}.  It always stays in the current frame. I checked the
> redirect_to code, it seems the method does not use "target". here is the
> source code of redirect_to from ActionController::Base
This topic is locked and can not be replied to.