Forum: Ruby on Rails URL rewriting

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5ee610e858812d3ce19941a85c5b99ef?d=identicon&s=25 Kevin (Guest)
on 2006-02-08 17:35
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.
F68e4842b0a5487678e26046fdb2fdf3?d=identicon&s=25 softwareengineer 99 (Guest)
on 2006-02-08 17:42
(Received via mailing list)
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 <khillabolt@gmail.com> 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/.
5ee610e858812d3ce19941a85c5b99ef?d=identicon&s=25 Kevin (Guest)
on 2006-02-08 17:48
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
This topic is locked and can not be replied to.