From fe3706e06c9a4a2e53932bc2b2ed4106ca86d405 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Mon, 13 Nov 2017 16:53:14 -0500 Subject: [PATCH 1/3] Regession in Resource generator for nested resources fixes #754 --- .../filetests/generate_resource_nested.json | 9 +++++++- generators/resource/generator_test.go | 16 ++++++++++++++ .../actions/resource-json-xml.go.tmpl | 16 +++++++------- .../actions/resource-use_model.go.tmpl | 22 +++++++++---------- .../templates/model-view-edit.html.tmpl | 4 ++-- .../templates/model-view-index.html.tmpl | 6 ++--- .../templates/model-view-show.html.tmpl | 4 ++-- meta/name.go | 5 +++++ meta/name_test.go | 16 ++++++++++++++ 9 files changed, 71 insertions(+), 27 deletions(-) create mode 100644 generators/resource/generator_test.go diff --git a/buffalo/cmd/filetests/generate_resource_nested.json b/buffalo/cmd/filetests/generate_resource_nested.json index 6f5ed6b3f..c3dc0a97d 100644 --- a/buffalo/cmd/filetests/generate_resource_nested.json +++ b/buffalo/cmd/filetests/generate_resource_nested.json @@ -2,7 +2,8 @@ "path": "actions/admin_planes.go", "contains": [ "type AdminPlanesResource struct", - "func (v AdminPlanesResource)" + "func (v AdminPlanesResource)", + "tx.Find(user, c.Param(\"admin_plane_id\"))" ] }, { @@ -29,5 +30,11 @@ "contains": [ "newAdminPlanesPath()" ] + }, + { + "path": "templates/admin/planes/show.html", + "contains": [ + "editAdminUserPath({ admin_plane_id: plane.ID })" + ] } ] diff --git a/generators/resource/generator_test.go b/generators/resource/generator_test.go new file mode 100644 index 000000000..433c2abe0 --- /dev/null +++ b/generators/resource/generator_test.go @@ -0,0 +1,16 @@ +package resource + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func Test_New_WithNestedName(t *testing.T) { + r := require.New(t) + + g, err := New("", "admin/user") + r.NoError(err) + name := g.Name + r.Equal("admin_user_id", name.ParamID()) +} diff --git a/generators/resource/templates/actions/resource-json-xml.go.tmpl b/generators/resource/templates/actions/resource-json-xml.go.tmpl index 9c0a5a697..6e8f6c70e 100644 --- a/generators/resource/templates/actions/resource-json-xml.go.tmpl +++ b/generators/resource/templates/actions/resource-json-xml.go.tmpl @@ -49,7 +49,7 @@ func (v {{.opts.Name.Resource}}Resource) List(c buffalo.Context) error { } // Show gets the data for one {{.opts.Model.Model}}. This function is mapped to -// the path GET /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.UnderSingular}}_id} +// the path GET /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.ParamID}}} func (v {{.opts.Name.Resource}}Resource) Show(c buffalo.Context) error { // Get the DB connection from the context tx := c.Value("tx").(*pop.Connection) @@ -57,8 +57,8 @@ func (v {{.opts.Name.Resource}}Resource) Show(c buffalo.Context) error { // Allocate an empty {{.opts.Model.Model}} {{.opts.Model.VarCaseSingular}} := &models.{{.opts.Model.Model}}{} - // To find the {{.opts.Model.Model}} the parameter {{.opts.Model.UnderSingular}}_id is used. - if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.UnderSingular}}_id")); err != nil { + // To find the {{.opts.Model.Model}} the parameter {{.opts.Model.ParamID}} is used. + if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.ParamID}}")); err != nil { return c.Error(404, err) } @@ -104,7 +104,7 @@ func (v {{.opts.Name.Resource}}Resource) Edit(c buffalo.Context) error { } // Update changes a {{.opts.Model.Model}} in the DB. This function is mapped to -// the path PUT /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.UnderSingular}}_id} +// the path PUT /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.ParamID}}} func (v {{.opts.Name.Resource}}Resource) Update(c buffalo.Context) error { // Get the DB connection from the context tx := c.Value("tx").(*pop.Connection) @@ -112,7 +112,7 @@ func (v {{.opts.Name.Resource}}Resource) Update(c buffalo.Context) error { // Allocate an empty {{.opts.Model.Model}} {{.opts.Model.VarCaseSingular}} := &models.{{.opts.Model.Model}}{} - if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.UnderSingular}}_id")); err != nil { + if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.ParamID}}")); err != nil { return c.Error(404, err) } @@ -135,7 +135,7 @@ func (v {{.opts.Name.Resource}}Resource) Update(c buffalo.Context) error { } // Destroy deletes a {{.opts.Model.Model}} from the DB. This function is mapped -// to the path DELETE /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.UnderSingular}}_id} +// to the path DELETE /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.ParamID}}} func (v {{.opts.Name.Resource}}Resource) Destroy(c buffalo.Context) error { // Get the DB connection from the context tx := c.Value("tx").(*pop.Connection) @@ -143,8 +143,8 @@ func (v {{.opts.Name.Resource}}Resource) Destroy(c buffalo.Context) error { // Allocate an empty {{.opts.Model.Model}} {{.opts.Model.VarCaseSingular}} := &models.{{.opts.Model.Model}}{} - // To find the {{.opts.Model.Model}} the parameter {{.opts.Model.UnderSingular}}_id is used. - if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.UnderSingular}}_id")); err != nil { + // To find the {{.opts.Model.Model}} the parameter {{.opts.Model.ParamID}} is used. + if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.ParamID}}")); err != nil { return c.Error(404, err) } diff --git a/generators/resource/templates/actions/resource-use_model.go.tmpl b/generators/resource/templates/actions/resource-use_model.go.tmpl index 17da0c044..83c4ae36d 100644 --- a/generators/resource/templates/actions/resource-use_model.go.tmpl +++ b/generators/resource/templates/actions/resource-use_model.go.tmpl @@ -52,7 +52,7 @@ func (v {{.opts.Name.Resource}}Resource) List(c buffalo.Context) error { } // Show gets the data for one {{.opts.Model.Model}}. This function is mapped to -// the path GET /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.UnderSingular}}_id} +// the path GET /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.ParamID}}} func (v {{.opts.Name.Resource}}Resource) Show(c buffalo.Context) error { // Get the DB connection from the context tx := c.Value("tx").(*pop.Connection) @@ -60,8 +60,8 @@ func (v {{.opts.Name.Resource}}Resource) Show(c buffalo.Context) error { // Allocate an empty {{.opts.Model.Model}} {{.opts.Model.VarCaseSingular}} := &models.{{.opts.Model.Model}}{} - // To find the {{.opts.Model.Model}} the parameter {{.opts.Model.UnderSingular}}_id is used. - if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.UnderSingular}}_id")); err != nil { + // To find the {{.opts.Model.Model}} the parameter {{.opts.Model.ParamID}} is used. + if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.ParamID}}")); err != nil { return c.Error(404, err) } @@ -120,7 +120,7 @@ func (v {{.opts.Name.Resource}}Resource) Create(c buffalo.Context) error { } // Edit renders a edit form for a {{.opts.Model.Model}}. This function is -// mapped to the path GET /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.UnderSingular}}_id}/edit +// mapped to the path GET /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.ParamID}}}/edit func (v {{.opts.Name.Resource}}Resource) Edit(c buffalo.Context) error { // Get the DB connection from the context tx := c.Value("tx").(*pop.Connection) @@ -128,7 +128,7 @@ func (v {{.opts.Name.Resource}}Resource) Edit(c buffalo.Context) error { // Allocate an empty {{.opts.Model.Model}} {{.opts.Model.VarCaseSingular}} := &models.{{.opts.Model.Model}}{} - if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.UnderSingular}}_id")); err != nil { + if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.ParamID}}")); err != nil { return c.Error(404, err) } @@ -138,7 +138,7 @@ func (v {{.opts.Name.Resource}}Resource) Edit(c buffalo.Context) error { } // Update changes a {{.opts.Model.Model}} in the DB. This function is mapped to -// the path PUT /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.UnderSingular}}_id} +// the path PUT /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.ParamID}}} func (v {{.opts.Name.Resource}}Resource) Update(c buffalo.Context) error { // Get the DB connection from the context tx := c.Value("tx").(*pop.Connection) @@ -146,7 +146,7 @@ func (v {{.opts.Name.Resource}}Resource) Update(c buffalo.Context) error { // Allocate an empty {{.opts.Model.Model}} {{.opts.Model.VarCaseSingular}} := &models.{{.opts.Model.Model}}{} - if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.UnderSingular}}_id")); err != nil { + if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.ParamID}}")); err != nil { return c.Error(404, err) } @@ -176,11 +176,11 @@ func (v {{.opts.Name.Resource}}Resource) Update(c buffalo.Context) error { c.Flash().Add("success", "{{.opts.Model.Model}} was updated successfully") // and redirect to the {{.opts.Name.URL}} index page - return c.Redirect(302, "/{{.opts.Name.URL}}/%s",{{.opts.Model.VarCaseSingular}}.ID) + return c.Redirect(302, "/{{.opts.Name.URL}}/%s",{{.opts.Model.ParamID}}) } // Destroy deletes a {{.opts.Model.Model}} from the DB. This function is mapped -// to the path DELETE /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.UnderSingular}}_id} +// to the path DELETE /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.ParamID}}} func (v {{.opts.Name.Resource}}Resource) Destroy(c buffalo.Context) error { // Get the DB connection from the context tx := c.Value("tx").(*pop.Connection) @@ -188,8 +188,8 @@ func (v {{.opts.Name.Resource}}Resource) Destroy(c buffalo.Context) error { // Allocate an empty {{.opts.Model.Model}} {{.opts.Model.VarCaseSingular}} := &models.{{.opts.Model.Model}}{} - // To find the {{.opts.Model.Model}} the parameter {{.opts.Model.UnderSingular}}_id is used. - if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.UnderSingular}}_id")); err != nil { + // To find the {{.opts.Model.Model}} the parameter {{.opts.Model.ParamID}} is used. + if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.ParamID}}")); err != nil { return c.Error(404, err) } diff --git a/generators/resource/templates/templates/model-view-edit.html.tmpl b/generators/resource/templates/templates/model-view-edit.html.tmpl index 2f17aacaf..53621b54d 100644 --- a/generators/resource/templates/templates/model-view-edit.html.tmpl +++ b/generators/resource/templates/templates/model-view-edit.html.tmpl @@ -2,7 +2,7 @@

Edit {{.opts.Model.Model}}

-<%= form_for({{.opts.Model.VarCaseSingular}}, {action: {{.opts.Name.VarCaseSingular}}Path({ {{.opts.Model.UnderSingular}}_id: {{.opts.Model.VarCaseSingular}}.ID }), method: "PUT"}) { %> +<%= form_for({{.opts.Model.VarCaseSingular}}, {action: {{.opts.Name.VarCaseSingular}}Path({ {{.opts.Model.ParamID}}: {{.opts.Model.VarCaseSingular}}.ID }), method: "PUT"}) { %> <%= partial("{{.opts.FilesPath}}/form.html") %> - Cancel + Cancel <% } %> diff --git a/generators/resource/templates/templates/model-view-index.html.tmpl b/generators/resource/templates/templates/model-view-index.html.tmpl index 7f789eb55..4691271ab 100644 --- a/generators/resource/templates/templates/model-view-index.html.tmpl +++ b/generators/resource/templates/templates/model-view-index.html.tmpl @@ -24,9 +24,9 @@ {{ end -}}
- View - Edit - Destroy + View + Edit + Destroy
diff --git a/generators/resource/templates/templates/model-view-show.html.tmpl b/generators/resource/templates/templates/model-view-show.html.tmpl index 1b9f8163c..2c8abc68d 100644 --- a/generators/resource/templates/templates/model-view-show.html.tmpl +++ b/generators/resource/templates/templates/model-view-show.html.tmpl @@ -4,8 +4,8 @@ {{ range $p := .opts.Props -}} diff --git a/meta/name.go b/meta/name.go index a66f2917c..fddd85dc9 100644 --- a/meta/name.go +++ b/meta/name.go @@ -1,6 +1,7 @@ package meta import ( + "fmt" "strings" "github.com/markbates/inflect" @@ -122,3 +123,7 @@ func (n Name) VarCasePlural() string { func (n Name) Lower() string { return strings.ToLower(string(n)) } + +func (n Name) ParamID() string { + return fmt.Sprintf("%s_id", strings.Replace(n.UnderSingular(), "/", "_", -1)) +} diff --git a/meta/name_test.go b/meta/name_test.go index a96a49e3a..a5b1ac88a 100644 --- a/meta/name_test.go +++ b/meta/name_test.go @@ -6,6 +6,22 @@ import ( "github.com/stretchr/testify/require" ) +func Test_Name_ParamID(t *testing.T) { + r := require.New(t) + table := []struct { + V string + E string + }{ + {V: "foo_bar", E: "foo_bar_id"}, + {V: "admin/widget", E: "admin_widget_id"}, + {V: "widget", E: "widget_id"}, + {V: "User", E: "user_id"}, + } + for _, tt := range table { + r.Equal(tt.E, Name(tt.V).ParamID()) + } +} + func Test_Name_Title(t *testing.T) { r := require.New(t) table := []struct { From 33306be2c6e35c87ad0e9220668ac11720ba2dac Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Mon, 13 Nov 2017 17:50:38 -0500 Subject: [PATCH 2/3] added doc --- meta/name.go | 1 + 1 file changed, 1 insertion(+) diff --git a/meta/name.go b/meta/name.go index fddd85dc9..1308740c4 100644 --- a/meta/name.go +++ b/meta/name.go @@ -124,6 +124,7 @@ func (n Name) Lower() string { return strings.ToLower(string(n)) } +// ParamID returns foo_bar_id func (n Name) ParamID() string { return fmt.Sprintf("%s_id", strings.Replace(n.UnderSingular(), "/", "_", -1)) } From 9ccda7226b2663a6d9a6fb5d4f06aa663fb6ee73 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Tue, 14 Nov 2017 13:51:05 -0500 Subject: [PATCH 3/3] hopefully fixed broken tests --- .../filetests/generate_resource_nested.json | 4 ++-- .../actions/resource-json-xml.go.tmpl | 16 +++++++------- .../actions/resource-use_model.go.tmpl | 22 +++++++++---------- .../templates/model-view-edit.html.tmpl | 4 ++-- .../templates/model-view-index.html.tmpl | 6 ++--- .../templates/model-view-show.html.tmpl | 4 ++-- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/buffalo/cmd/filetests/generate_resource_nested.json b/buffalo/cmd/filetests/generate_resource_nested.json index c3dc0a97d..fee35f17f 100644 --- a/buffalo/cmd/filetests/generate_resource_nested.json +++ b/buffalo/cmd/filetests/generate_resource_nested.json @@ -3,7 +3,7 @@ "contains": [ "type AdminPlanesResource struct", "func (v AdminPlanesResource)", - "tx.Find(user, c.Param(\"admin_plane_id\"))" + "tx.Find(plane, c.Param(\"admin_plane_id\"))" ] }, { @@ -34,7 +34,7 @@ { "path": "templates/admin/planes/show.html", "contains": [ - "editAdminUserPath({ admin_plane_id: plane.ID })" + "editAdminPlanePath({ admin_plane_id: plane.ID })" ] } ] diff --git a/generators/resource/templates/actions/resource-json-xml.go.tmpl b/generators/resource/templates/actions/resource-json-xml.go.tmpl index 6e8f6c70e..5bfcf00f5 100644 --- a/generators/resource/templates/actions/resource-json-xml.go.tmpl +++ b/generators/resource/templates/actions/resource-json-xml.go.tmpl @@ -49,7 +49,7 @@ func (v {{.opts.Name.Resource}}Resource) List(c buffalo.Context) error { } // Show gets the data for one {{.opts.Model.Model}}. This function is mapped to -// the path GET /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.ParamID}}} +// the path GET /{{.opts.Name.URL}}/{{"{"}}{{.opts.Name.ParamID}}} func (v {{.opts.Name.Resource}}Resource) Show(c buffalo.Context) error { // Get the DB connection from the context tx := c.Value("tx").(*pop.Connection) @@ -57,8 +57,8 @@ func (v {{.opts.Name.Resource}}Resource) Show(c buffalo.Context) error { // Allocate an empty {{.opts.Model.Model}} {{.opts.Model.VarCaseSingular}} := &models.{{.opts.Model.Model}}{} - // To find the {{.opts.Model.Model}} the parameter {{.opts.Model.ParamID}} is used. - if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.ParamID}}")); err != nil { + // To find the {{.opts.Model.Model}} the parameter {{.opts.Name.ParamID}} is used. + if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Name.ParamID}}")); err != nil { return c.Error(404, err) } @@ -104,7 +104,7 @@ func (v {{.opts.Name.Resource}}Resource) Edit(c buffalo.Context) error { } // Update changes a {{.opts.Model.Model}} in the DB. This function is mapped to -// the path PUT /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.ParamID}}} +// the path PUT /{{.opts.Name.URL}}/{{"{"}}{{.opts.Name.ParamID}}} func (v {{.opts.Name.Resource}}Resource) Update(c buffalo.Context) error { // Get the DB connection from the context tx := c.Value("tx").(*pop.Connection) @@ -112,7 +112,7 @@ func (v {{.opts.Name.Resource}}Resource) Update(c buffalo.Context) error { // Allocate an empty {{.opts.Model.Model}} {{.opts.Model.VarCaseSingular}} := &models.{{.opts.Model.Model}}{} - if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.ParamID}}")); err != nil { + if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Name.ParamID}}")); err != nil { return c.Error(404, err) } @@ -135,7 +135,7 @@ func (v {{.opts.Name.Resource}}Resource) Update(c buffalo.Context) error { } // Destroy deletes a {{.opts.Model.Model}} from the DB. This function is mapped -// to the path DELETE /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.ParamID}}} +// to the path DELETE /{{.opts.Name.URL}}/{{"{"}}{{.opts.Name.ParamID}}} func (v {{.opts.Name.Resource}}Resource) Destroy(c buffalo.Context) error { // Get the DB connection from the context tx := c.Value("tx").(*pop.Connection) @@ -143,8 +143,8 @@ func (v {{.opts.Name.Resource}}Resource) Destroy(c buffalo.Context) error { // Allocate an empty {{.opts.Model.Model}} {{.opts.Model.VarCaseSingular}} := &models.{{.opts.Model.Model}}{} - // To find the {{.opts.Model.Model}} the parameter {{.opts.Model.ParamID}} is used. - if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.ParamID}}")); err != nil { + // To find the {{.opts.Model.Model}} the parameter {{.opts.Name.ParamID}} is used. + if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Name.ParamID}}")); err != nil { return c.Error(404, err) } diff --git a/generators/resource/templates/actions/resource-use_model.go.tmpl b/generators/resource/templates/actions/resource-use_model.go.tmpl index 83c4ae36d..a032389c7 100644 --- a/generators/resource/templates/actions/resource-use_model.go.tmpl +++ b/generators/resource/templates/actions/resource-use_model.go.tmpl @@ -52,7 +52,7 @@ func (v {{.opts.Name.Resource}}Resource) List(c buffalo.Context) error { } // Show gets the data for one {{.opts.Model.Model}}. This function is mapped to -// the path GET /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.ParamID}}} +// the path GET /{{.opts.Name.URL}}/{{"{"}}{{.opts.Name.ParamID}}} func (v {{.opts.Name.Resource}}Resource) Show(c buffalo.Context) error { // Get the DB connection from the context tx := c.Value("tx").(*pop.Connection) @@ -60,8 +60,8 @@ func (v {{.opts.Name.Resource}}Resource) Show(c buffalo.Context) error { // Allocate an empty {{.opts.Model.Model}} {{.opts.Model.VarCaseSingular}} := &models.{{.opts.Model.Model}}{} - // To find the {{.opts.Model.Model}} the parameter {{.opts.Model.ParamID}} is used. - if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.ParamID}}")); err != nil { + // To find the {{.opts.Model.Model}} the parameter {{.opts.Name.ParamID}} is used. + if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Name.ParamID}}")); err != nil { return c.Error(404, err) } @@ -120,7 +120,7 @@ func (v {{.opts.Name.Resource}}Resource) Create(c buffalo.Context) error { } // Edit renders a edit form for a {{.opts.Model.Model}}. This function is -// mapped to the path GET /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.ParamID}}}/edit +// mapped to the path GET /{{.opts.Name.URL}}/{{"{"}}{{.opts.Name.ParamID}}}/edit func (v {{.opts.Name.Resource}}Resource) Edit(c buffalo.Context) error { // Get the DB connection from the context tx := c.Value("tx").(*pop.Connection) @@ -128,7 +128,7 @@ func (v {{.opts.Name.Resource}}Resource) Edit(c buffalo.Context) error { // Allocate an empty {{.opts.Model.Model}} {{.opts.Model.VarCaseSingular}} := &models.{{.opts.Model.Model}}{} - if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.ParamID}}")); err != nil { + if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Name.ParamID}}")); err != nil { return c.Error(404, err) } @@ -138,7 +138,7 @@ func (v {{.opts.Name.Resource}}Resource) Edit(c buffalo.Context) error { } // Update changes a {{.opts.Model.Model}} in the DB. This function is mapped to -// the path PUT /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.ParamID}}} +// the path PUT /{{.opts.Name.URL}}/{{"{"}}{{.opts.Name.ParamID}}} func (v {{.opts.Name.Resource}}Resource) Update(c buffalo.Context) error { // Get the DB connection from the context tx := c.Value("tx").(*pop.Connection) @@ -146,7 +146,7 @@ func (v {{.opts.Name.Resource}}Resource) Update(c buffalo.Context) error { // Allocate an empty {{.opts.Model.Model}} {{.opts.Model.VarCaseSingular}} := &models.{{.opts.Model.Model}}{} - if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.ParamID}}")); err != nil { + if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Name.ParamID}}")); err != nil { return c.Error(404, err) } @@ -176,11 +176,11 @@ func (v {{.opts.Name.Resource}}Resource) Update(c buffalo.Context) error { c.Flash().Add("success", "{{.opts.Model.Model}} was updated successfully") // and redirect to the {{.opts.Name.URL}} index page - return c.Redirect(302, "/{{.opts.Name.URL}}/%s",{{.opts.Model.ParamID}}) + return c.Redirect(302, "/{{.opts.Name.URL}}/%s",{{.opts.Model.VarCaseSingular}}.ID) } // Destroy deletes a {{.opts.Model.Model}} from the DB. This function is mapped -// to the path DELETE /{{.opts.Name.URL}}/{{"{"}}{{.opts.Model.ParamID}}} +// to the path DELETE /{{.opts.Name.URL}}/{{"{"}}{{.opts.Name.ParamID}}} func (v {{.opts.Name.Resource}}Resource) Destroy(c buffalo.Context) error { // Get the DB connection from the context tx := c.Value("tx").(*pop.Connection) @@ -188,8 +188,8 @@ func (v {{.opts.Name.Resource}}Resource) Destroy(c buffalo.Context) error { // Allocate an empty {{.opts.Model.Model}} {{.opts.Model.VarCaseSingular}} := &models.{{.opts.Model.Model}}{} - // To find the {{.opts.Model.Model}} the parameter {{.opts.Model.ParamID}} is used. - if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Model.ParamID}}")); err != nil { + // To find the {{.opts.Model.Model}} the parameter {{.opts.Name.ParamID}} is used. + if err := tx.Find({{.opts.Model.VarCaseSingular}}, c.Param("{{.opts.Name.ParamID}}")); err != nil { return c.Error(404, err) } diff --git a/generators/resource/templates/templates/model-view-edit.html.tmpl b/generators/resource/templates/templates/model-view-edit.html.tmpl index 53621b54d..b1ce0e46a 100644 --- a/generators/resource/templates/templates/model-view-edit.html.tmpl +++ b/generators/resource/templates/templates/model-view-edit.html.tmpl @@ -2,7 +2,7 @@

Edit {{.opts.Model.Model}}

-<%= form_for({{.opts.Model.VarCaseSingular}}, {action: {{.opts.Name.VarCaseSingular}}Path({ {{.opts.Model.ParamID}}: {{.opts.Model.VarCaseSingular}}.ID }), method: "PUT"}) { %> +<%= form_for({{.opts.Model.VarCaseSingular}}, {action: {{.opts.Name.VarCaseSingular}}Path({ {{.opts.Name.ParamID}}: {{.opts.Model.VarCaseSingular}}.ID }), method: "PUT"}) { %> <%= partial("{{.opts.FilesPath}}/form.html") %> - Cancel + Cancel <% } %> diff --git a/generators/resource/templates/templates/model-view-index.html.tmpl b/generators/resource/templates/templates/model-view-index.html.tmpl index 4691271ab..42d4c38aa 100644 --- a/generators/resource/templates/templates/model-view-index.html.tmpl +++ b/generators/resource/templates/templates/model-view-index.html.tmpl @@ -24,9 +24,9 @@ {{ end -}} diff --git a/generators/resource/templates/templates/model-view-show.html.tmpl b/generators/resource/templates/templates/model-view-show.html.tmpl index 2c8abc68d..43941d24e 100644 --- a/generators/resource/templates/templates/model-view-show.html.tmpl +++ b/generators/resource/templates/templates/model-view-show.html.tmpl @@ -4,8 +4,8 @@ {{ range $p := .opts.Props -}}