How to do url rewriting

Hello,

I am Amit. i am new to Rails. Please forgive me if ask any stupid
questions.

I have gone through this article. I am also suffering with the same
problem.

my website URL like this: http://127.0.0.0:3000/users/edit/30

I don’t want to show the controller:users and action: edit.

I want to Re-Write (rewrite) the URL or i want to maintain the URL as
http://127.0.0.0:3000/30/ only.(30 is a user id)

I am not interested to show the controller(user) and action (edit)

I total intention is to Hiding (HIDING) and rewriting (REWRING) the URL
and mainly i want to hide the URL Extensions with controller and actions
mainly…

Can u help me on that… Please…!!! sad

Hello Amit!

What the purpose to hide the controller and action from URL?

You can use the Apache mod_rewrite itself to make this change. You will
need to know a little regex to make these changes.

Amit Jain wrote:

Hello,

I am Amit. i am new to Rails. Please forgive me if ask any stupid
questions.

I have gone through this article. I am also suffering with the same
problem.

my website URL like this: http://127.0.0.0:3000/users/edit/30

I don’t want to show the controller:users and action: edit.

I want to Re-Write (rewrite) the URL or i want to maintain the URL as
http://127.0.0.0:3000/30/ only.(30 is a user id)

I am not interested to show the controller(user) and action (edit)

I total intention is to Hiding (HIDING) and rewriting (REWRING) the URL
and mainly i want to hide the URL Extensions with controller and actions
mainly…

Can u help me on that… Please…!!! sad

Look at my response to your message “how can i hide controller and
action
name in url”.

There is a link there to a Rails guide which explains all about Routing.
Routing is the part of rails that defined mapping a URL or URL pattern
to a
controller and action.

At the moment you seem to be multiple posting the same question, phrased
slightly differently without reading responses.

Cheers,

Andy


Andy J.
http://andyjeffries.co.uk/ #rubyonrails #mysql #jquery
Registered address: 64 Sish Lane, Stevenage, Herts, SG1 3LS
Company number: 5452840

What the purpose to hide the controller and action from URL?

To have nicer URLs? For example:
http://www.facebook.com/andyjeffriesrather than
http://www.facebook.com/user/show/andyjeffries

It’s quite a common request.

You can use the Apache mod_rewrite itself to make this change. You will

need to know a little regex to make these changes.

You can, but given that Rails has native support for this in the Routing
subsystem I’d personally avoid putting it in the webserver (otherwise if
you
want to move to something else, Nginx, Unicorn, whatever) you’d have to
redo
the work.

Cheers,

Andy

You can add a custom route to do that, but with the pattern you suggest,
it may be tough to add other controllers as it breaks many rails
conventions.

in Rails 2.3’s routes.rb file:

map.edit_user “:id”, :controller => “users”, :action => “edit”, :id =>
/\d/

The regex on ID is to prevent this route from matching other routes you
may have in your app that follow Rails conventions. It ensures the ID
is a number. You would also need to remove the “edit” route from the
user resource by adding :except => [:edit].

But I strongly urge against this. With the pattern you’ve described
wanting to apply to all URLs, the routing engine will have no way to
determine what you actually want it to do for example:

GET http://localhost:3000/30

Does that reference the edit action for the users controller for id 30,
or the show action for posts with id 30, or the show action for users
with id 30, etc?

With such a short url, ambiguity and difficulty in growing the app for
the url collisions is what you will have.

Niels

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs