Redirecting in a view?


#1

Is there a way to do this in a view?

<% redirect_to ‘http://url.com’ %>

All I can think of is outputting a link and using
Javascript to click it, or probably do something like
‘doc.location(url)’.

csn


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


#2

You could use a meta refresh if it is supposed to be after a set time
limit.


#3

Ben R. wrote:

You could use a meta refresh if it is supposed to be after a set time
limit.

Would that work in BODY though? Where I want to redirect is in a
template that goes in @content_for_layout in between body tags.

csn


#4

You can send back some javascript, off the top of my head it would be:

<%= javascript_tag
‘document.location=“http://www.domain.com/link.html”;’ %>

Cheers, Jonny.

csn wrote:

Ben R. wrote:

You could use a meta refresh if it is supposed to be after a set time
limit.

Would that work in BODY though? Where I want to redirect is in a
template that goes in @content_for_layout in between body tags.

csn


#5

Why does your controller not have enough information to make this
decision,
but your view does?

This type of work should be kept out of the view code and kept in the
controller. That’s what MVC is about, and will help you in the future
when
your app needs to be maintained.


#6

Sounds like its trying to control something. This is a good job for the
controller.


#7

Tom F. wrote:

Why does your controller not have enough information to make this
decision,
but your view does?

This type of work should be kept out of the view code and kept in the
controller. That’s what MVC is about, and will help you in the future
when
your app needs to be maintained.

I agree ;). But it’s just a generic sub template that does one of the
following:

  • links to a file (image, flash)
  • includes another file (text)
  • renders a template in a database field
  • or (hopefully) redirects to another site

csn