jhu-ep-coursera / fullstack-course3-module1-zips

Ruby on Rails Web Services and Integration with MongoDB - Coursera Course
48 stars 91 forks source link

correct a single error #3

Open josie00 opened 8 years ago

ejavaguy commented 8 years ago

Why do you believe the code is in error? Your change looks like it would eliminate the prototype passed in (replacing it with {}) and cause all records to be selected instead of those that match the prototype expressed by the hash.

On Thu, May 5, 2016 at 3:40 AM, Josie Liu notifications@github.com wrote:


You can view, comment on, or merge this pull request online at:

https://github.com/jhu-ep-coursera/fullstack-course3-module1-zips/pull/3 Commit Summary

  • correct a single error

File Changes

Patch Links:

- https://github.com/jhu-ep-coursera/fullstack-course3-module1-zips/pull/3.patch

https://github.com/jhu-ep-coursera/fullstack-course3-module1-zips/pull/3.diff

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/jhu-ep-coursera/fullstack-course3-module1-zips/pull/3

josie00 commented 8 years ago

Probably the "params" could be changed to "params[:prototype]", since the params also include parameters such as "limit", "offset" and "sort"

ejavaguy commented 8 years ago

params also include parameters such as "limit", "offset" and "sort"

:prototype is not a URI query parameter. The prototype fields are at the root level. The slice() call within model.all() acts as an ad-hoc white-listing implementation (instead of "params.require" and "include") and strips out anything that is not :city or :state.

https://github.com/jhu-ep-coursera/fullstack-course3-module1-zips/blob/master/app/models/zip.rb#L57 prototype=prototype.symbolize_keys.slice(:city, :state) if !prototype.nil?

I won't argue that this is exactly the way Rails would do it, but it does work the way it is implemented. Rails scaffold would have scoped the "city" and "state" below a root node of "zip". Since we are pushing most of the pedals ourselves, we got a chance to make up a few of our own rules (before we learn all the conventions).

On Tue, May 10, 2016 at 4:55 AM, Josie Liu notifications@github.com wrote:

Probably the "params" could be changed to "params[:prototype]", since the params also include parameters such as "limit", "offset" and "sort"

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/jhu-ep-coursera/fullstack-course3-module1-zips/pull/3#issuecomment-218097721

josie00 commented 8 years ago

Ok. Thank you very much!