Jump to content

The ultimate community for Ruby on Rails developers.


Routes - Having trouble understanding them.

routes ruby-on-rails ruby

  • Please log in to reply
1 reply to this topic

#1 catMad



  • Members
  • 1 posts

Posted 03 April 2014 - 08:31 PM

Hi all,


I'm having a lot of trouble understanding routes.


Not stuff like root to => controller/index ... but other stuff ...


Not sure why I'm having so much trouble understanding it.


The guides are are not really that helpful to me:http://guides.rubyon...rg/routing.html


Not saying that it's badly written, etc. People do advocate it pretty often.


It's just I'm not getting it.


Are there any other resources that could help my understanding of routes?


If yes, please do let me know if it as I'm getting rather frustrated with myself and lack of understanding when it comes to routes.



#2 Alain ANDRE



  • Members
  • 6 posts
  • LocationBordeaux

Posted 07 April 2014 - 09:36 AM

Well, I think http://guides.rubyon...rg/routing.html is the best you can find.


What is important to understand is that basically, the routes are the allowed REST routes to your application by the rails router.


You can specify a REST route to your action with on simple line :

# Allow the update of User with the PUT method on the URL/path profile/update
put 'profile/update/', to: 'users#update'

And you can allow all the REST routes to a model of your app with resources :

# Allow put, delete, post, get of a Photo
resources :photos

You can also allow only a few REST routes to a model like this :

resources :photos, only: [:index, :show]

With this last one, you will be able photos/index and photos/show. photos/delete or other will not be able.


Hope it helps.

Also tagged with one or more of these keywords: routes, ruby-on-rails, ruby

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users