<meta http-equiv="refresh" content="5"/>

48 views
Skip to first unread message

David

unread,
Sep 12, 2008, 8:38:42 PM9/12/08
to Ruby on Rails: Talk
Do you know of any way for me to stick a meta tag in using a
before_filter or after_filter or around_filter?

<meta http-equiv="refresh" content="5"/>

I have been trying to figure out out and just cannot make sense of it.

Christian Rishøj

unread,
Sep 13, 2008, 7:38:10 PM9/13/08
to Ruby on Rails: Talk

You could use the content_for pattern. Set the header as he content in
your filter, and output it in your view.

Christian

Ryan Bigg

unread,
Sep 13, 2008, 8:09:38 PM9/13/08
to rubyonra...@googlegroups.com
What Christian means is something like:

Put this in your app/views/layouts/application.html.erb:

<%= yield :refresh_tag %>

And then you will need to call this in a view:

<% content_for :refresh_tag do %>
> <meta http-equiv="refresh" content="5"/>
<% end %>


But this needs to be done in a view... unlike the requested
before_filter and after_filter.

You could set a variable in the before filter and wrap the code in an
if statement:

class ForumsController < ApplicationController
before_filter :refresh, :only => :show

# ...
private

def refresh
@refresh = true
end
end

Then in your application.html.erb:

<% if @refresh %>
> <meta http-equiv="refresh" content="5"/>
<% end %>


-----
Ryan Bigg
Freelancer
Skype: radarlistener
MSN & Gtalk: radarl...@gmail.com
Reply all
Reply to author
Forward
0 new messages