https://github.com/cimon-io/susanin
Extend `polymorphic_url` to replace simple resource with array of resources.
https://github.com/cimon-io/susanin
activesupport billet routes ruby ruby-gem ruby-on-rails rubyonrails
Last synced: 15 days ago
JSON representation
Extend `polymorphic_url` to replace simple resource with array of resources.
- Host: GitHub
- URL: https://github.com/cimon-io/susanin
- Owner: cimon-io
- License: mit
- Fork: true (aratak/susanin)
- Created: 2015-05-29T08:27:47.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-12-29T12:20:19.000Z (almost 4 years ago)
- Last Synced: 2024-04-26T13:20:52.263Z (over 1 year ago)
- Topics: activesupport, billet, routes, ruby, ruby-gem, ruby-on-rails, rubyonrails
- Language: Ruby
- Size: 33.2 KB
- Stars: 15
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Susanin
Extend `polymorphic_url` to replace simple resource with array of resources.
## Installation
Add this line to your application's Gemfile:
gem 'susanin'
And then execute:
$ bundle
Or install it yourself as:
$ gem install susanin
## Usage
By default gems do nothing. Include module 'susanin' to the controller.
```ruby
class ApplicationController < ActionController::Base
include ::Susaninsusanin do
[
[:owner, ->(r) { [:admin] }],
[[:frontend, Link], ->(r) { [:frontend, r] }],
[User, ->(r) { [:owner, r] }],
[Project, ->(r) { [:owner, r] }],
[Link, ->(r) { [:owner, r] }],
[Admin, ->(r) { [r.company, r] }],
[Photo, ->(r) { [r.admin.company, r.admin, r] }],
[Gallery, ->(r) { [r.company, r] }]
]
endend
```Then you're able to call `link_to` method wihtout knowlege about the nested resources inside `routes.rb`. Instead of this:
```ruby
link_to user.email, [:edit, user.company, user], class: 'button'
```You are able to write this:
```ruby
link_to user.email, [:edit, user], class: 'button'
```## Contributing
1. Fork it ( https://github.com/[my-github-username]/susanin/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request