-
-
Notifications
You must be signed in to change notification settings - Fork 577
Resource generator --use-model #297 fixes #328 #333
Conversation
This reverts commit 45cc609.
I ran it's output:
The package actions
import "github.com/gobuffalo/buffalo"
type UserResource struct {
buffalo.Resource
}
// List default implementation.
func (v UserResource) List(c buffalo.Context) error {
return c.Render(200, r.String("User#List"))
}
// Show default implementation.
func (v UserResource) Show(c buffalo.Context) error {
return c.Render(200, r.String("User#Show"))
}
// New default implementation.
func (v UserResource) New(c buffalo.Context) error {
return c.Render(200, r.String("User#New"))
}
// Create default implementation.
func (v UserResource) Create(c buffalo.Context) error {
return c.Render(200, r.String("User#Create"))
}
// Edit default implementation.
func (v UserResource) Edit(c buffalo.Context) error {
return c.Render(200, r.String("User#Edit"))
}
// Update default implementation.
func (v UserResource) Update(c buffalo.Context) error {
return c.Render(200, r.String("User#Update"))
}
// Destroy default implementation.
func (v UserResource) Destroy(c buffalo.Context) error {
return c.Render(200, r.String("User#Destroy"))
} |
func (v {{.camel}}Resource) List(c buffalo.Context) error { | ||
// Get the DB connection from the context | ||
tx := c.Value("tx").(*pop.Connection) | ||
{{.downFirstCap}} := &models.{{.camel}}{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be plural.
It's generating user := &models.User{}
, but it should be users := &models.Users{}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that resources are always generated with plural args: buffalo g resource users name email bio:text
then the logic works. But I am going to change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The model stuff is just implemented with the --use-model
flag. Because otherwise the tests will fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the tests need to be fixed. The --use-model
flag should be used if you have an existing model, but the default, without any flags, should generate everything.
It's ok in the Dockerfile to delete stuff that was previously generated in the tests, or to create a new app, etc...
This should generate all of the <h1>Users#List</h1>
Find me at templates/users/list.html |
|
OMG! This is sooooooooo awesome!! I'm really excited about this! Just started testing it, but so far so good! I can't wait to get this into I have a few notes, but nothing big, as far as I can tell. |
// If there are no errors set a success message | ||
c.Flash().Add("success", "{{.model}} was created successfully") | ||
// and redirect to the {{.underPlural}} index page | ||
return c.Redirect(301, "/{{.underPlural}}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have this redirect to the Show
action. /users/1234
// If there are no errors set a success message | ||
c.Flash().Add("success", "{{.model}} was edited successfully") | ||
// and redirect to the {{.underPlural}} index page | ||
return c.Redirect(301, "/{{.underPlural}}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have this redirect to the Show
action. /users/1234
if err != nil { | ||
return err | ||
} | ||
// Redirect to the {{.underPlural}} index page |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a flash message here to say that it was deleted.
// If there are no errors set a success message | ||
c.Flash().Add("success", "{{.model}} was created successfully") | ||
// and redirect to the {{.underPlural}} index page | ||
return c.Redirect(301, "/{{.underPlural}}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a 302
.
// If there are no errors set a success message | ||
c.Flash().Add("success", "{{.model}} was edited successfully") | ||
// and redirect to the {{.underPlural}} index page | ||
return c.Redirect(301, "/{{.underPlural}}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a 302
.
return err | ||
} | ||
// Redirect to the {{.underPlural}} index page | ||
return c.Redirect(301, "/{{.underPlural}}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a 302
.
buffalo/cmd/generate/resource.go
Outdated
var SkipResourceModel = false | ||
|
||
// UseResourceModel allows to generate a resource with a working model. | ||
var UseResourceModel = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a string
containing the name of the model to use.
buffalo g resource users --use-model=user
Some issues with pluralization:
In var userResource buffalo.Resource
userResource = UserResource{&buffalo.BaseResource{}}
app.Resource("/user", userResource) But the resource is named |
It looks like the happy path is working great!
These still have issues:
|
|
htmltemplates
Basic set of html templates are now generated. |
I fixed a few bugs and cleaned up some of the HTML. |
Generates a basic implementation for a resource, which supports crud functionality for a existing model.