{"action":"created","issue":{"url":"https://api.github.com/repos/hanami/hanami/issues/465","repository_url":"https://api.github.com/repos/hanami/hanami","labels_url":"https://api.github.com/repos/hanami/hanami/issues/465/labels{/name}","comments_url":"https://api.github.com/repos/hanami/hanami/issues/465/comments","events_url":"https://api.github.com/repos/hanami/hanami/issues/465/events","html_url":"https://github.com/hanami/hanami/issues/465","id":127949046,"number":465,"title":"Param errors exposed to views and templates","user":{"login":"nomanurrehman","id":7188724,"avatar_url":"https://avatars.githubusercontent.com/u/7188724?v=3","gravatar_id":"","url":"https://api.github.com/users/nomanurrehman","html_url":"https://github.com/nomanurrehman","followers_url":"https://api.github.com/users/nomanurrehman/followers","following_url":"https://api.github.com/users/nomanurrehman/following{/other_user}","gists_url":"https://api.github.com/users/nomanurrehman/gists{/gist_id}","starred_url":"https://api.github.com/users/nomanurrehman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nomanurrehman/subscriptions","organizations_url":"https://api.github.com/users/nomanurrehman/orgs","repos_url":"https://api.github.com/users/nomanurrehman/repos","events_url":"https://api.github.com/users/nomanurrehman/events{/privacy}","received_events_url":"https://api.github.com/users/nomanurrehman/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hanami/hanami/labels/discussion","name":"discussion","color":"0052cc"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-01-21T15:25:50Z","updated_at":"2016-07-11T13:36:25Z","closed_at":"2016-07-11T13:36:25Z","body":"I have found that when there are validation errors in case of params, the variable \"errors\" is automatically exposed to views and templates.\r\n\r\nI started out with my controller like this:\r\n\r\n```ruby\r\n\r\nmodule Web::Controllers::Users\r\n  class Create\r\n    include Web::Action\r\n\r\n    params do\r\n      param :data do\r\n        param :user do\r\n          param :first_name, presence: true, size: 5..25\r\n          param :last_name, presence: true, size: 5..25\r\n          param :username, presence: true, size: 5..25\r\n          param :password, presence: true, size: 8..64\r\n          param :date_of_birth\r\n        end\r\n      end\r\n    end\r\n\r\n    expose :user, :errors\r\n\r\n    def call(params)\r\n      if params.valid?\r\n        create_user(params)\r\n      else\r\n        @errors = params.errors\r\n      end\r\n    end\r\n\r\n    private\r\n\r\n    def create_user(params)\r\n      @user = UserRepository.create(User.new(\r\n        first_name: params.get('data.user.first_name'),\r\n        last_name: params.get('data.user.last_name'),\r\n        username: params.get('data.user.username'),\r\n        password: params.get('data.user.password'),\r\n        date_of_birth: params.get('data.user.date_of_birth')\r\n      ))\r\n    end\r\n\r\n  end\r\nend\r\n```\r\n\r\nGoing with the framework's \"explicit\" approach, this is more natural and explains the code a bit better to someone who is looking at it for the first time.\r\n\r\nMoreover, in case there are no validation errors, an empty hash `{}` is still exposed to the view and templates.\r\n\r\nThe problem arose for me when I tried to set a custom error in case, say the database is down. The errors variable is still an empty hash `{}` in that case.\r\n\r\nI think exposing the errors should be made explicit as compared to implicitly being passed to views and templates.\r\n\r\nAlso, I did not find this mentioned in the documentation anywhere or did I miss it?\r\n\r\nThoughts?"},"comment":{"url":"https://api.github.com/repos/hanami/hanami/issues/comments/231735862","html_url":"https://github.com/hanami/hanami/issues/465#issuecomment-231735862","issue_url":"https://api.github.com/repos/hanami/hanami/issues/465","id":231735862,"user":{"login":"jodosha","id":5089,"avatar_url":"https://avatars.githubusercontent.com/u/5089?v=3","gravatar_id":"","url":"https://api.github.com/users/jodosha","html_url":"https://github.com/jodosha","followers_url":"https://api.github.com/users/jodosha/followers","following_url":"https://api.github.com/users/jodosha/following{/other_user}","gists_url":"https://api.github.com/users/jodosha/gists{/gist_id}","starred_url":"https://api.github.com/users/jodosha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodosha/subscriptions","organizations_url":"https://api.github.com/users/jodosha/orgs","repos_url":"https://api.github.com/users/jodosha/repos","events_url":"https://api.github.com/users/jodosha/events{/privacy}","received_events_url":"https://api.github.com/users/jodosha/received_events","type":"User","site_admin":false},"created_at":"2016-07-11T13:36:25Z","updated_at":"2016-07-11T13:36:25Z","body":"I'm closing this because we want to implement a different way to pass errors to the views."}}
{"actor":{"display_login":"jodosha"}}