Closed cpjk closed 9 years ago
:+1: this!
Hate to see <%= @loaded_resource.name %>
in the view layer!
Thanks for letting me know!
I'm thinking of inferring the name through naming conventions, while also allowing the user to specify the target variable with something like plug load_resource model: Project.User, as: :user
.
I'll look at implementing the as
flag as soon as possible, while I am figuring out the best way to implement the variable name inference.
Great! Good to see such an early start on an important project like this!
I've pushed up some preliminary changes to https://github.com/cpjk/canary/tree/fix_double_loading
that implement opts[:as] for resource loading, e.g. load_resource model: User, as: :user
.
There's no model inference yet, but I think this is a good start.
Added another commit to infer the name from the model specified in the plug.
For example, plug load_resource, model: Project.Post
will load the resource into conn.assigns.post
and plug load_resource, model: Project.BlogPost
would load the resource into conn.assigns.blog_post
:+1: Awesome!
Closing the issue as the changes were merged into master over the weekend
For example,
plug :load_resource, model: Project.User
would load the user resource into conn.assigns.user, which would then be available in views as@user