I am using Ruby on Rails 3. In my project I have many classes and some of those are stated in the routes.rb file like the following:
#routers.rb
resources :users
namespace "users" do
resources :profiles
...
end
With the above code I can access the following URLs:
<my_web_site>/users/1
<my_web_site>/users/1/edit
...
# and also
<my_web_site>/users/profiles/1
<my_web_site>/users/profiles/1/edit
...
What I would like to do is to redirect some URL requests to others URL but if in the routes.rb file I redirect all those, some controller actions will not work properly because also those requests are redirected (GET, POST, …).
How can I solve this issue?
P.S.: I know that (maybe) my router statements are wrong, but at the moment I am looking for a easy solution too the problem. However suggestions about this matter are welcome.
Ok, looks like you want to set up a redirection that will only apply for to a given path and just one HTTP verb. This seems to be what you are looking for:
Based on this routes every
GETrequest hitting/users/profile/1will be redirected to/profiles/1while anyPOST,PUTorDELETErequests won’t be suffering the redirection.The
:viaparam will execure the redirection only if the request method math the given value. It also accepts an array of verbs so, for example, you can redirect:via => [:post, :put]If you add more detailed information about the specific redirections that you need we can create a better example.