Forum: Ruby on Rails Redirecting in a view?

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.
CSN (Guest)
on 2006-01-21 23:05
(Received via mailing list)
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
Ben R. (Guest)
on 2006-01-21 23:34
(Received via mailing list)
You could use a meta refresh if it is supposed to be after a set time
limit.

<meta http-equiv="Refresh"
content="4;url=http://www.domain.com/link.html">
csn (Guest)
on 2006-01-21 23:37
Ben R. wrote:
> You could use a meta refresh if it is supposed to be after a set time
> limit.
>
> <meta http-equiv="Refresh"
> content="4;url=http://www.domain.com/link.html">

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
Jonathan V. (Guest)
on 2006-01-21 23:39
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.
>>
>> <meta http-equiv="Refresh"
>> content="4;url=http://www.domain.com/link.html">
>
> 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
Tom F. (Guest)
on 2006-01-21 23:53
(Received via mailing list)
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.
csn (Guest)
on 2006-01-22 04:39
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
Tom F. (Guest)
on 2006-01-22 05:19
(Received via mailing list)
Sounds like its trying to control something.  This is a good job for the
controller.
This topic is locked and can not be replied to.