Joined June 2013
·

Zane Wolfgang Pickett

Buzzword Compliant Full Stack Web Developer
·
United States
·
·
·

Posted to Redirect to back or default in Rails over 1 year ago

Wanted to make a small amendment. Add *args so that you can pass through other options like notices.

def redirect_to_back_or_default(default = root_url, *args)
  if request.env['HTTP_REFERER'].present? && request.env['HTTP_REFERER'] != request.env['REQUEST_URI']
    redirect_to :back, *args
  else
    redirect_to default, *args
  end
end
Posted to Writing Great Documentation over 1 year ago

That reminds me, I found this awhile back for business logic: http://brewhouse.io/blog/2014/04/30/gourmet-service-objects.html

I think it solve the problem in most cases rather nicely.

Posted to Writing Great Documentation over 1 year ago

Certain systems do gain stuff like auto complete from some basic comments, outside of that; I would argue that the function name should tell you everything you need to know. If you can't describe what something does in its name, your probably trying to solve too many problems in that function.

I also forgot to point out how tests are often the best documentation for functions.

You can load all your ENV vars to the application in the same place: But I tend to agree with 12 factors in that things should be based on ENV vars so that you can deploy without worrying about config files. This also works really well from things like Docker.

http://12factor.net/config

Achievements
117 Karma
1,182 Total ProTip Views
Interests & Skills