URL rewriting


#1

Here is the scenario I am trying to achieve. Basically, I want to run
the action “show” from my controller, without adding the “show/id”.

Standard:
http://www.domain.com/controllerName/show/id

I would like:
http://www.domain.com/controllerName/randomstring (where randomstring is
a
field in my model/table, that is equivalent to a GUID -> and unique).

I’m confused at how this would be possible, because you normally would
create an action in the controller, that is then used in the url.
Would this be a URL rewrite that would need to be added to .htaccess?
If so, the I would have to some how change the “show” action to not
use “id”?

Thanks for any help you can provide.


#2

I believe you don’t need URL rewriting for this.

I was trying to something similar so instead of
http://domain.com/post/id
it will use http://domain/post/title

and I ended up using something like:

map.connect ‘post/:mytitle’, :controller => “yourController”, :action
=> ‘show’

Look around in routes.rb file.

Hope this helps.

Frank

Kevin removed_email_address@domain.invalid wrote: Here is the scenario I am trying to
achieve. Basically, I want to run
the action “show” from my controller, without adding the “show/id”.

Standard:
http://www.domain.com/controllerName/show/id

I would like:
http://www.domain.com/controllerName/randomstring (where randomstring is
a
field in my model/table, that is equivalent to a GUID -> and unique).

I’m confused at how this would be possible, because you normally would
create an action in the controller, that is then used in the url.
Would this be a URL rewrite that would need to be added to .htaccess?
If so, the I would have to some how change the “show” action to not
use “id”?

Thanks for any help you can provide.


Posted via http://www.ruby-forum.com/.


#3

Hi Frank,

That looks like exactly what I was looking for. I will give it a try.

Thanks for your help…

Kevin

softwareengineer 99 wrote:

I believe you don’t need URL rewriting for this.

I was trying to something similar so instead of
http://domain.com/post/id
it will use http://domain/post/title

and I ended up using something like:

map.connect ‘post/:mytitle’, :controller => “yourController”, :action
=> ‘show’

Look around in routes.rb file.

Hope this helps.

Frank