go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Step 3 -- Create a new resource
 
Subject: Step 3 -- Create a new resource
Author: Linux
In response to: Traffic flow
Posted on: 09/12/2017 01:55:13 AM

What is resource?
A resource is the term used for a collection of similar objects, such as organization, people or books. You can create, read, update and destroy items for a resource and these operations are referred to as CRUD operations.

Rails provides a resources method which can be used to declare a standard REST resource. For example, you can add a posts resource to the config/routes.rb for your blog.

Rails.application.routes.draw do
  get 'welcome/index'

  resources :posts

  root 'welcome#index'  
end


And then run:
administrator@ubuntu:~/blog$ rails routes
       Prefix Verb   URI Pattern               Controller#Action
welcome_index GET    /welcome/index(.:format)  welcome#index
        posts GET    /posts(.:format)          posts#index
              POST   /posts(.:format)          posts#create
     new_post GET    /posts/new(.:format)      posts#new
    edit_post GET    /posts/:id/edit(.:format) posts#edit
         post GET    /posts/:id(.:format)      posts#show
              PATCH  /posts/:id(.:format)      posts#update
              PUT    /posts/:id(.:format)      posts#update
              DELETE /posts/:id(.:format)      posts#destroy
         root GET    /                         welcome#index


This shows that you have a complete CRUD actions implicitly ready inside the routing table.


 

> On 09/12/2017 01:30:11 AM Linux wrote:



                         /config/routes.rb     app/controllers/welcome_controller.rb    
http://localhost:3000/ -------------------->  ----------------------------------------> 
                                ^                     ^   
                                |                     |
                         root 'welcome#index'    def index
                                                  // default to view --> app/views/welcome/index.html.erb
                                                 end







References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.