Topic: Action-caching

I have a blog_controller where each page has 3 states.

1) Normal view
2) Admin mode, which displays the page as normal but adds a little "edit this page" button and a "last updated at" label
3) This page is protected, you the user gets redirected p

Re: Action-caching

You can use a subdomain for the admin section of your site (admin.example.com) which would look the same but just show the admin links when the user is logged in as an admin. This way you can add page caching to the public side.

However, I'm not sure about problem 3 you mentioned. What logic determines when the page is protected? Perhaps you need action caching instead.

Railscasts - Free Ruby on Rails Screencasts

Re: Action-caching

ryanb wrote:

However, I'm not sure about problem 3 you mentioned. What logic determines when the page is protected? Perhaps you need action caching instead.

it's just a tag in the database. The site is just my personal little blog/wiki (well, a wiki only I can edit) and I implemented a tagging system for all the pages. If a page isn't tagged as public you (i.e. me) has to log in.
The whole redirect-thing isn't very pretty but I just had to get it working smile any improvments are welcome (I'm sure there's lot of room for it).

I basicly just have this in my controller:

if !admin? and !@post.is_public
  flash[:notice] = "Unauthorized access"
  redirect_to login_url
  false
else

and is public just is:
def is_public
  !tags.find(:first, :conditions => { :value => 'public' }).nil?
end

Re: Action-caching

If you go with the "admin" subdomain then that should solve this problem as well since an admin won't be considered an admin in the public domain.

Railscasts - Free Ruby on Rails Screencasts