Skip to content

Instantly share code, notes, and snippets.

@nickhoffman
Created January 10, 2012 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickhoffman/1590041 to your computer and use it in GitHub Desktop.
Save nickhoffman/1590041 to your computer and use it in GitHub Desktop.
An alternative to halting in a helper
get '/users/:user_id/projects/:project_id/tasks-due-on/:task_date' do
user = User.find(params[:user_id])
halt 404 unless user
project = user.projects.find(params[:project_id])
halt 404 unless project
# etc...
end
@batasrki
Copy link

It mixes error handling code with the happy path code. I know what your concern is and there must be a balance.

@nickhoffman
Copy link
Author

I don't see why error handling and the happy path should be separated, though. You don't split them in model methods, so why split them in controller actions?

Yes, multiply-nested conditionals are fugly. However, as I've shown above, they're not necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment