Replacing Default Routes for a Resource in Rails 3

I have a resource defined like this:

resources :referrals, :except => [:show, :edit, :destroy]

and I would like to replace (and not just add a named route) with the default route that Rails creates, in particular for the update action.

Here are my rake routes:

referrals    GET  /referrals(.:format)     {:action=>"index", :controller=>"referrals"}
             POST /referrals(.:format)     {:action=>"create", :controller=>"referrals"}
new_referral GET  /referrals/new(.:format) {:action=>"new", :controller=>"referrals"}
referral     PUT  /referrals/:id(.:format) {:action=>"update", :controller=>"referrals"}
share             /share(.:format)         {:controller=>"referrals", :action=>"new"}
special           /special(.:format)       {:controller=>"referrals", :action=>"index"}
thanks            /thanks(.:format)        {:controller=>"pages", :action=>"thanks"}
                  /:shortlink(.:format)    {:controller=>"referrals", :action=>"update"}
                  /:linktext(.:format)     {:controller=>"referrals", :action=>"update"}
root              /(.:format)              {:controller=>"pages", :action=>"home"}

I would like either

/:shortlink(.:format)

or

/:linktext(.:format)

to click update action but not

/referrals/:id(.:format)

This is an implementation of a security form without a password. When PUT goes into the update action, I want some things to happen, but I do not want to require authorization for this, and I do not want to allow easy guessing of the URL based on the name of the controller and simple low-level applications, numbered identifiers.

How can I completely replace the default route given by rails?

+5
1

resources :referrals, :except => [:show, :edit, :destroy, :update]

match "/whatever_you_want/:variable_here" => "referrals#updated", :as=> the_link, :via=> :put

params[:variable_here]

- , db, :

the_link_path the_link_url

: HTTP-,

http://guides.rubyonrails.org/routing.html

+2

All Articles