{"id":17303329,"url":"https://github.com/mikker/render_with_view","last_synced_at":"2025-04-14T13:11:08.057Z","repository":{"id":52436113,"uuid":"60596451","full_name":"mikker/render_with_view","owner":"mikker","description":"☝️ Be explicit about the things you send from your Rails controller to the view.","archived":false,"fork":false,"pushed_at":"2023-08-29T11:41:47.000Z","size":20,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T02:13:58.554Z","etag":null,"topics":["rails","rails-controller","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mikker.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-07T08:34:28.000Z","updated_at":"2024-04-29T19:09:28.000Z","dependencies_parsed_at":"2025-02-25T11:33:28.861Z","dependency_job_id":"d7026a7f-bd6c-4edc-ab43-6be4d2d49bba","html_url":"https://github.com/mikker/render_with_view","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/mikker%2Frender_with_view","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikker%2Frender_with_view/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikker%2Frender_with_view/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikker%2Frender_with_view/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikker","download_url":"https://codeload.github.com/mikker/render_with_view/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248822695,"owners_count":21167100,"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":["rails","rails-controller","ruby"],"created_at":"2024-10-15T11:50:08.946Z","updated_at":"2025-04-14T13:11:07.632Z","avatar_url":"https://github.com/mikker.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# render_with_view\n\nBe explicit about the things you send from your Rails controller to the view.\n\n### Example\n\n`app/controllers/application_controller.rb`:\n\n```ruby\nclass ApplicationController\n  include RenderWithView\nend\n```\n\n`app/controllers/home_controller.rb`:\n\n```ruby\nclass HomeController \u003c ApplicationController\n  def index\n    render_with_view posts: Post.all\n  end\nend\n```\n\n`app/views/home/index.html.erb`:\n\n```erb\n\u003cul\u003e\n  \u003c% view.posts.each do |post| %\u003e\n    \u003cli\u003e\u003c%= link_to post.title, post %\u003e\u003c/li\u003e\n  \u003c% end %\u003e\n\u003c/ul\u003e\n```\n\n### Why not just use instance variables?\n\nThey feel like _magic_. Instead I like how this forces me to be explicit in what I send along to my templates. It's like a small step towards having a presenter/view layer (or whatever) but not going further than just adding the convention of using a single variable.\n\n### What's `view`?\n\nAn object with reader methods for every key in the hash you gave it. A [HalfOpenStruct](https://gist.github.com/henrik/19c68b2a41ab4d098ce8) in a way.\n\n## Installation\n\nAdd `render_with_view` to your Gemfile:\n\n```ruby\ngem 'render_with_view'\n```\n\nInclude it in your `ApplicationController`:\n\n```ruby\nclass ApplicationController\n  include RenderWithView\nend\n```\n\n## Bonus RSpec matcher\n\n```ruby\nrequire 'render_with_view/rspec_matcher'\n\ndescribe ThingController do\n  subject { get :index }\n  it { should set_view_local :key, optional_value }\nend\n```\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikker%2Frender_with_view","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikker%2Frender_with_view","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikker%2Frender_with_view/lists"}