views:

142

answers:

1

How do I "name" a browser window in ROR, such that I can open a page in it later, from another (popup) window (using the target="name" html parameter)

+5  A: 

You have to use JavaScript for this:

<script type="text/javascript">
  window.name = "MyWindow";
</script>

Of course you could easily package this up into a Rails helper method. For example, in app/helpers/application_helper.rb add a new method:

def window_name(name)
  content_for(:window_name) do
    "<script type=\"text/javascript\">window.name = \"#{name}\";</script>"
  end
end

Next, in your layout file, add this line somewhere within the HTML <head> element:

<%= yield :window_name %>

Finally, in your view templates, simply add a line like this (can be anywhere you want) to output the correct JavaScript:

<% window_name 'MyWindow' %>
John Topley