# Restful Routing and restful versus non-restful routes

**URL:** <https://www.ruby-forum.com/t/restful-routing-and-restful-versus-non-restful-routes/237533>\
**Category:** Rails\
**Created:** [November 18, 2013, 10:30am UTC](https://www.ruby-forum.com/t/restful-routing-and-restful-versus-non-restful-routes/237533 "2013-11-18T10:30:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [November 18, 2013, 10:30am UTC](https://www.ruby-forum.com/t/restful-routing-and-restful-versus-non-restful-routes/237533/1 "2013-11-18T10:30:59Z")

</div>

So resources :products will create 7 different restful routes for CRUD  
operations for resource products.  
For example: products GET /products(.:format) products#index

So restful route includes only controller name within itself and :id for  
operation like edit, show, update, delete.  
When i create _non-restful_ routes in rails for example: get  
‘:controller/:action/:id’ i only can see difference that i  
_must_explicitly write  
:action, so that “:action” makes this route non-restful?

_So as i get this, first requirement for route(URL) to be restful is  
that  
route can’t contain action name?_ _Question 1_

Second requirement for route to be restful is that action corresponding  
to  
route must “play by restful rules” in another word,  
for example a GET should not leave side-effects on the server, but just  
retrieve data.  
So if i have /products(.:format) products#index and within index action  
i  
saved something into DB, _than above route is just looks like restful  
route  
but in fact it isn’t_? _Question 2_

I know that i can pass to restful route additional parameters, for  
example:  
link\_to “Show”, products\_path(id: 5, a: “aaaa”, b: “bbbb”) so now URL  
is:  
products/5?a=aaaa&b=bbbb.  
So am i violating restful here, or this route is still restful?  
_Question 3_

To me seems that i don’t need _non_-restful routes at all, when i can  
make  
a bunch of restful routes with construct like following?(and other  
similar  
construct)  
_Question 4_

resources :products do  
member do  
get ‘preview’  
endend

Please don’t redirect me to [Rails Routing from the Outside In — Ruby on Rails Guides](http://guides.rubyonrails.org/routing.html) i  
read it multiple times 🙂

---

<div class="post-metadata">

**Author:** ![Srdjan\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@Srdjan\_C](https://www.ruby-forum.com/u/Srdjan_C)\
**Post date:** [November 18, 2013, 10:54am UTC](https://www.ruby-forum.com/t/restful-routing-and-restful-versus-non-restful-routes/237533/2 "2013-11-18T10:54:21Z")

</div>

On 18 November 2013 09:29, Srdjan C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [snip]  
> Question 1
> 
> Second requirement for route to be restful is that action corresponding to  
> route must “play by restful rules” in another word,  
> for example a GET should not leave side-effects on the server, but just  
> retrieve data.  
> So if i have /products(.:format) products#index and within index action i  
> saved something into DB, than above route is just looks like restful route  
> but in fact it isn’t?

Whether it is restful or not is not relevant as you should not do  
this. Imagine, for example, the havoc caused when google interrogates  
all the GET routes in your application.

> Question 2
> 
> I know that i can pass to restful route additional parameters, for example:  
> link\_to “Show”, products\_path(id: 5, a: “aaaa”, b: “bbbb”) so now URL is:  
> products/5?a=aaaa&b=bbbb.  
> So am i violating restful here, or this route is still restful?

It is still restful.

> end  
> end

So what is the question you are asking? If the restful routes fit  
your needs then use them, if they don’t then use other routes.

Colin
