ruby - Rake task to create a Rails partial from json data -
right have helper:
def blog_posts rails.cache.fetch("blog_posts", :expires_in => 30.minutes) url = uri('http://www.xxxxxxxx.com/blog/?json=get_recent_posts') request = net::http.get(url) response = json.parse(request) response['posts'].take(4) end rescue => e logger.error "error retrieving blog posts!" logger.error "#{e.message}\n#{e.backtrace.join("\n")}" [] end and view have:
<% blog_posts.each |blog| %> <div class="col col-3"> <a class="search-page-links" href="<%= blog['url'] %>" target="_blank"> <img class="post-image" src="<%= blog['thumbnail'] %>"> <br/><br/> <%= blog['title'].html_safe %> </a> </div> <% end %> which works fine. except dont want data pulled when page loads @ anymore, because cant count on source. plan add rake task deploy process static data can updated in rails partial @ each deploy, rendered view. how go doing this?
creating partials sound worst possible solution because creating huge amount of code duplication, , potentially huge slug (deployed code base). if have save json data disk , use fragment caching if needed.
other alternatives use key/value or json based storage instead of storing data in codebase (which bad idea).
i sit down client or whoever making rules , explain pretty big maintenance problem down line , suggest solution tenable.
Comments
Post a Comment