{"id":15412518,"url":"https://github.com/elmassimo/presenter_rails","last_synced_at":"2025-04-19T09:43:53.712Z","repository":{"id":14474580,"uuid":"17186772","full_name":"ElMassimo/presenter_rails","owner":"ElMassimo","description":"🔭 Expose your view models in a convenient way","archived":false,"fork":false,"pushed_at":"2022-04-11T23:00:22.000Z","size":24,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-14T08:51:36.778Z","etag":null,"topics":["presenters","rails","views"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"clef/handbook","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ElMassimo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-25T20:17:45.000Z","updated_at":"2023-11-28T09:47:52.000Z","dependencies_parsed_at":"2022-09-13T18:21:52.836Z","dependency_job_id":null,"html_url":"https://github.com/ElMassimo/presenter_rails","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElMassimo%2Fpresenter_rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElMassimo%2Fpresenter_rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElMassimo%2Fpresenter_rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElMassimo%2Fpresenter_rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ElMassimo","download_url":"https://codeload.github.com/ElMassimo/presenter_rails/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249666757,"owners_count":21308153,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["presenters","rails","views"],"created_at":"2024-10-01T16:53:36.185Z","updated_at":"2025-04-19T09:43:53.615Z","avatar_url":"https://github.com/ElMassimo.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Presenter [![Gem Version](https://badge.fury.io/rb/presenter_rails.svg)](https://rubygems.org/gems/presenter_rails) [![Build Status](https://github.com/ElMassimo/presenter_rails/workflows/build/badge.svg)](https://github.com/ElMassimo/presenter_rails/actions) [![Test Coverage](https://codeclimate.com/github/ElMassimo/presenter_rails/badges/coverage.svg)](https://codeclimate.com/github/ElMassimo/presenter_rails) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ElMassimo/presenter_rails/blob/master/LICENSE.txt)\n=====================\n\nPresenter helps you expose view models to your views in a convenient way, while\nstill allowing you to define methods with the same name inside your controllers.\n\n```ruby\n # app/controllers/people_controller.rb\n class PeopleController \u003c ApplicationController\n\n    present(:person) {\n      PersonDecorator.decorate(person)\n    }\n\n    ...\n\n    def person\n      People.find(params[:id])\n    end\n end\n```\n\n```haml\n / app/views/people/show.html.haml\n .person\n   .person-name= person.name\n   .person-info= person.biography\n```\n\nThe method is also available in the controller, with a `_presenter` suffix:\n```ruby\n # app/controllers/people_controller.rb\n class PeopleController \u003c ApplicationController\n\n    present(:person) {\n      PersonDecorator.decorate(person)\n    }\n\n    def update\n      person.update(attrs)\n      redirect_to person_presenter.path, notice: \"Successfully updated.\"\n    end\n\n    ...\n\n end\n```\n\n## Background\nPresenter attempts to simplify the exposure of variables to the views. It doesn't really care\nabout what you are exposing, although it's specially useful to implement [two-step views](http://martinfowler.com/eaaCatalog/twoStepView.html) while using\n[view models](https://github.com/drapergem/draper) in combination with [resourcerer](https://github.com/ElMassimo/resourcerer).\n\n### How it works\n\nWhen you provide a block, it defines a `\"#{name}_presenter\"` private method in your controller.\n\nAfter that, it creates a helper method for your views, which calls the `\"#{name}_presenter\"` counterpart in the controller.\n\n#### Memoization\nEach presenter method is memoized, so the method is called only once and your views get the same instance every time. The block is evaluated only if the method is called.\n\n#### Corolary\nSince the helper methods defined are only available for the view, you can define methods with the same name in your controller :smiley:\n\nCredits\n--------\nPresenter was crafted to use in combination with [resourcerer](https://github.com/ElMassimo/resourcerer).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felmassimo%2Fpresenter_rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felmassimo%2Fpresenter_rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felmassimo%2Fpresenter_rails/lists"}