3 ms·
Upvoted because I like your solution for pagination and for further information via an :href attribute. However, I don't see a real problem with the way Rails d
by bphogan 15y ago
Upvoted because I like your solution for pagination and for further information via an :href attribute. However, I don't see a real problem with the way Rails does things because it's "by default" and I think a dev ends up causing a lot of unnecessary trouble for himself by using stock to_json. The more I work with Rails building out a JSON API, the more I realize that .to_json is just another way to "scaffold" - it's not useful in production. :)
- awj 15y agoI can see that point ... but where's the direction on what to do next? What's the post-scaffold JSON mechanism? Bonus points if it lets me generate/embed urls with the knowledge/techniques I have from making web pages. If you say "erb", please don't be offended by me laughing.
- rbxbx 15y agoPerhaps something along the lines of the following would provide a good balance http://quickleft.com/blog/presenters-as-a-solution-to-asjson-woes-in-rails-apis http://quickleft.com/blog/presenters-as-a-solution-to-asjson... It's also worth noting that to_json should not be invoked directly these days in favor of as_json. It's now meant to more or less be an internal Rails API.
- bphogan 15y agoOh please ;) Don't hate on the ERb. It's fine for something like this. OK, I am only half-kidding. Have you seen RABL? I've been meaning to play with this. http://blog.dcxn.com/2011/06/22/rails-json-templates-through-rabl/ http://blog.dcxn.com/2011/06/22/rails-json-templates-through... Looks perfect.