Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • routes and resources in ruby

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 304
    Comment on it

    If you are new to ruby then you must have wondered about what is routes in ruby, so today I will discuss everything about routes in detail. Rail routes are used to dispatch URl to the controllers action. it is used to generate path for particular action in the ruby. method to assign routes

    
    get 'users/13'
    
    

    this route will be used to get the information of id 13 of user in show action inside the controller. If you will type rake routes in console you will see the below text

    
    get '/users/:id', to: 'users#show', as: 'user'
    
    

    It will hit the show method in your specific controller Resources routing in rails, resource routing is used to generate all the routes necessary for particular controller it generates all the method such as GET, POST, PATCH, PUT and DELETE. each method is used to perform specific action on the resource.

     

    How we define resource in config/routes.rb file

    
    resources :users
    
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: