# Rewriting URLs - help needed

**URL:** <https://www.ruby-forum.com/t/rewriting-urls-help-needed/65417>\
**Category:** Rails\
**Created:** [August 18, 2006, 2:48am UTC](https://www.ruby-forum.com/t/rewriting-urls-help-needed/65417 "2006-08-18T02:48:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Gansen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b77776/32.png) [@Chris\_Gansen](https://www.ruby-forum.com/u/Chris_Gansen)\
**Post date:** [August 18, 2006, 2:48am UTC](https://www.ruby-forum.com/t/rewriting-urls-help-needed/65417/1 "2006-08-18T02:48:42Z")

</div>

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/](http://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

---

<div class="post-metadata">

**Author:** ![Chris\_Gansen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b77776/32.png) [@Chris\_Gansen](https://www.ruby-forum.com/u/Chris_Gansen)\
**Post date:** [August 18, 2006, 10:49am UTC](https://www.ruby-forum.com/t/rewriting-urls-help-needed/65417/2 "2006-08-18T10:49:56Z")

</div>

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/](http://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

---

<div class="post-metadata">

**Author:** ![Chris\_Gansen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b77776/32.png) [@Chris\_Gansen](https://www.ruby-forum.com/u/Chris_Gansen)\
**Post date:** [August 18, 2006, 6:05pm UTC](https://www.ruby-forum.com/t/rewriting-urls-help-needed/65417/3 "2006-08-18T18:05:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chris\_Gansen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b77776/32.png) [@Chris\_Gansen](https://www.ruby-forum.com/u/Chris_Gansen)\
**Post date:** [August 18, 2006, 8:27pm UTC](https://www.ruby-forum.com/t/rewriting-urls-help-needed/65417/4 "2006-08-18T20:27:10Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Chris\_Gansen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b77776/32.png) [@Chris\_Gansen](https://www.ruby-forum.com/u/Chris_Gansen)\
**Post date:** [August 18, 2006, 6:17pm UTC](https://www.ruby-forum.com/t/rewriting-urls-help-needed/65417/5 "2006-08-18T18:17:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chris\_Gansen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b77776/32.png) [@Chris\_Gansen](https://www.ruby-forum.com/u/Chris_Gansen)\
**Post date:** [August 18, 2006, 10:00pm UTC](https://www.ruby-forum.com/t/rewriting-urls-help-needed/65417/6 "2006-08-18T22:00:23Z")

</div>

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](http://wiki.script.aculo.us/scriptaculous/show/VisualEffects) for  
other visual effects (fade, slide\_down, etc) you can use.

cheers,  
Jodi

---

<div class="post-metadata">

**Author:** ![Chris\_Gansen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b77776/32.png) [@Chris\_Gansen](https://www.ruby-forum.com/u/Chris_Gansen)\
**Post date:** [August 18, 2006, 10:18pm UTC](https://www.ruby-forum.com/t/rewriting-urls-help-needed/65417/7 "2006-08-18T22:18:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chris\_Gansen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b77776/32.png) [@Chris\_Gansen](https://www.ruby-forum.com/u/Chris_Gansen)\
**Post date:** [August 18, 2006, 10:06pm UTC](https://www.ruby-forum.com/t/rewriting-urls-help-needed/65417/8 "2006-08-18T22:06:24Z")

</div>

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
