Rewriting URLs - help needed

Hello -

I’m grappling with some tricky URL rewriting with Apache 2 and
mod_rewrite,
and could use a hand.

Briefly:

URL for application is: www.servername.com/path/to/app/

There is no Alias directive; the application is in the directory
/www/content/path/to/app/ on the server file system.

The FastCGI dispatcher (dispatch.fcgi) lives at:

/www/fcgi-bin/path/to/app/dispatch.fcgi

Inside my .htaccess file, there is the standard rewrite rules:

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /fcgi-bin/path/to/app/dispatch.fcgi [QSA,L]

Problem: EVERYTHING is sent to dispatch.fcgi, which errors out, since it
cannot recognize the full URL string, which looks like:
“/path/to/app/controller/action”

What should I do?

Thanks!
–chris

Chris Gansen <cgansen@…> writes:

Hello -I’m grappling with some tricky URL rewriting with Apache 2 and
mod_rewrite, and could use a hand.Briefly:URL for application is:
www.servername.com/path/to/app/
There is no Alias directive; the application is in the directory
/www/content/path/to/app/ on the server file system.The FastCGI
dispatcher
(dispatch.fcgi) lives at:/www/fcgi-bin/path/to/app/dispatch.fcgi
Inside my .htaccess file, there is the standard rewrite rules:RewriteRule ^$
index.html [QSA]RewriteRule ^([^.]+)$ $1.html [QSA]RewriteCond
%{REQUEST_FILENAME} !-fRewriteRule ^(.*)$
/fcgi-bin/path/to/app/dispatch.fcgi
[QSA,L]
Problem: EVERYTHING is sent to dispatch.fcgi, which errors out, since it
cannot recognize the full URL string, which looks like:
"/path/to/app/controller/action"What should I do?Thanks!
–chris

The simplest way to so this is to put your rails directory outside the
webroot,
so it’s not diretly accessible, and then instead of having a
[webroot]/path/to/app folder, make [webroot]/path/to/app a symlink to
the
[/path/to/rails/app]/public folder. Rails should pick up the fact that
it’s been
symlinked, and the helpers should prepend the correct path. I think

I’ve just started learning Ruby and am having some problems with partial
templates. Here’s what I have:

  1. I’ve created a layout page that has page headers and footers
  2. I’ve created a main index page that displays a list of product.
  3. I’ve created a view called ‘tags_for_product.rhtml’ that displays
    related tags for a product

What I would like to do is to have a link next to each product in the
list on the index page that says “show tags for product”. By clicking
this, the tags for the product should be displayed using AJAX. If I use
the link_to_remote tag, I can link to the tags_for_product action, but
the problem is that it renders the entire tags_for_product.rhtml page
along with the headers and footers from the main layout which is a huge
mess. Am I going about this the wrong way? What’s a better way to do
that? Thanks in advance.

Best Regards,

Tamim

Hi Jodi,

Thank you for the info. I do have the partial named
‘_tags_for_product.rhtml’. The problem with using ‘render :partial’ is
that it will render the partial immediately. I want to be able to have a
link that I click that can toggle the display of the info on and off.
Here’s what I mean:
http://www.tmpforums.com/temp/tags.avi
I was able to achieve the above by getting rid of my main layout file
and create two separate layout files in the shared directory, one for
the header and one for the footer. I rendered the header and footer in
the main page but not the original tags_for_product.rhtml page. Then I’m
using link_to_remote to link to the tags_for_product.rhtml page. It
works, but I suspect it’s not the best way to do it because I really
don’t want to include headers and footers on numerous pages.

Best Regards,

Tamim

Hello Tamin,

you’ll then want ‘tags_for_product.rhtml’ to be called
'_‘tags_for_product.rhtml’ (the naming convent for partials).

then your controller action (that responds to the link_to_remote)

render :partial => ‘tags_for_product’ #note the missing _ - it’s
assumed to be prefixed to the name

that’s it.

Jodi

Tamim - I’m confused about your layouts question - does it help that
you can render without layout with render :partial =>
‘partial_name’, :layout => false ?

To show/hide your tag info using :loaded (or :success) to indicate
that your :update div should be shown.

something like:

      <%= link_to_remote("tags",
                                :update => 'tag-info',
                                :success => "new Effect.Appear

(‘tag-info’)",
:url => { :action =>
‘show_product_tags’, :id => @product %>

check out wiki.script.aculo.us/scriptaculous/show/VisualEffects for
other visual effects (fade, slide_down, etc) you can use.

cheers,
Jodi

that’s how I’d do it Tamin.

you probably don’t want the :loaded and :success though (both will be
called when success happens).

cya.
Jodi

Thanks Jodi. Actually, that’s what I’m using now. I actually have two
divs (one with the show link and one with the hide link) and they each
toggle the other. Here’s a snippet of what I’m using:

<span id="product<%= product.id %>show">[ <%= link_to_remote ("Show

Tags",
:update => “product#{product.id}tags”,
:loading =>
%(Element.hide(“product#{product.id}show”)),
:loaded =>
%(Element.show(“product#{product.id}hide”)),
:success =>
%(Element.show(“product#{product.id}tags”)),
:url => {
:action => “tags_for_product”,
:id => product.id
}) %> ]


[ <%=
link_to_remote (“Hide Tags”,
:update => “product#{product.id}tags”,
:loading =>
%(Element.show(“product#{product.id}show”)),
:loaded =>
%(Element.hide(“product#{product.id}hide”)),
:success =>
%(Element.hide(“product#{product.id}tags”)),
:url => {
:action => “none”,
}) %> ]

I know you can over-ride the layout usage on a partial (actually I don’t
think partials use the layouts anyway), but can you over-ride the use of
a layout on a regular view page? Basically I don’t want the layout to be
applied to tags_for_product.rhtml. Thanks again.

Best Regards,

Tamim