Re: Q&A about REST, namespaced controllers, authentication and authorization

paron
Thu, 29 Mar 2007 17:05:54 -0000

On Feb 23, 3:47 am, "diegal"
<diego.algo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

> According to the
> sources I''ve studied, this could also bring some caching problems
too
> because it practically nullifies the possibility of using page and
> actioncache.

I think you are asking excellent questions. Here''s an approach that I
am investigating for caching:

Since neither an editable (form) page nor a simple display page alters
the data, they should both be available via http GET.  However, the
scaffold_resource generator produces an architecture that uses a query
string (;edit) to specify which page is wanted. The query string is
ignored by page caching. So, when you GET "/documents/1", it caches
the display page, and when you GET "/documents/1;edit", it gets the
display page out of the cache instead of making a nice editable form
with the data inserted.

I think it''s more appropriate to treat alternative html formats as
just that; formats. I might send a request like "/documents/
1.html_edit" (You have to add that mime type to the environment.rb,
like:

.
.
.
 Mime::Type.register "text/html", :html_edit
.
.
.
Now, that "works" as far as being recognized by page caching:
everything gets cached and served from cache.You have to add
"caches_page :index, :show"


to the controller. The corresponding "show" method looks like:

  # GET /documents/1
  # GET /documents/1.xml
  # GET /documents/1.html_edit
  def show
    @document = Document.find(params[:id])

    respond_to do |format|
      format.html # show.rhtml
      format.html_edit {render ''documents/edit''}
      format.xml  { render :xml => @document.to_xml }
    end
  end


However, expiring the cache isn''t pretty:
in my controller''s "update" action, for instance, I added:
.
.
.
       #expires /public/documents.html
       expire_page(:controller=>''documents'')

       #expires  /public/1.html (the show.rhtml result)
        expire_page(:controller=>''documents'',
:action=>'''',:id =>
@document)

       #expires /public/show/1.html_edit

expire_page(:controller=>''documents'',
:action=>''show'',
:id=>"#{@document.id}.html_edit")
.
.
.
to get everything to clean up properly. Ugly.

I think perhaps multiple controllers is a good idea. What did you end
up trying?

Ron