firstdraft / draft_generators

Rails generators that help beginners learn to program.
MIT License
2 stars 3 forks source link

Resolve #58 - Use Golden 5 routes with json endpoints #60

Closed jelaniwoods closed 4 years ago

jelaniwoods commented 5 years ago

Routes are now written like this:

  match("/insert_model", { :controller => "models", :action => "create", :via => "post"})

  # READ
  match("/models", { :controller => "models", :action => "index", :via => "get"})

  match("/models/:rt_model_id", { :controller => "models", :action => "show", :via => "get"})

  # UPDATE

  match("/modify_model/:rt_model_id", { :controller => "models", :action => "update", :via => "post"})

  # DELETE
  match("/delete_model/:rt_model_id", { :controller => "models", :action => "destroy", :via => "get"})

Controller actions render like:

    respond_to do |format|
      format.json do
        render({ :json => @model.as_json })
      end

      format.html do
        render({ :template => "models/show.html.erb" })
      end
    end

View folders now generate just as the plural model name instead of singular_table_name_templates.

I made a test repo here

You can also add this to the Gemfile of an existing rails app

  gem 'draft_generators', github: 'firstdraft/draft_generators', branch: "jw-use-golden-5-routes"

Then run

rails g draft:resource task name:string due_on:datetime