Sha256: d4b51e75e1be8a85848e1a38237770239aa6204e2ad427311330b5f62678a404
Contents?: true
Size: 1.74 KB
Versions: 1
Compression:
Stored size: 1.74 KB
Contents
# asset\_pipeline\_routes [](https://travis-ci.org/nicolai86/asset_pipeline_routes) [](http://badge.fury.io/rb/asset_pipeline_routes) `asset_pipeline_routes` defines a `r` shorthand function which you can use inside your javascript assets. ## What it does Assuming you got a `routes.rb` with: ``` ruby resources :users # => yields multiple routes, e.g. /users/:id(.:format) ``` Inside your javascript assets you can now write: ``` javascript r(users_path) // => yields '/users' r(user_path) // => yields '/users/{{id}}' r(user_path, userId) // => yields '/users/'+userId ``` It works with coffeescript as well: ``` coffeescript promise = $.rails.ajax({ url: r(user_path, userId) }) ``` If you are compiling client side templates with the rails asset pipeline this works inside templates as well, e.g. ``` hamlbars %form{ action: r(user_path) } ``` will generate ``` html <form action='/users/{{id}}'></form> ``` ## Upgrading Notes *v0.2* introduced code breaking changes! **THIS WILL NO LONGER WORK** ``` erb // inside application.js.erb var url = '<%= r.user_path 42 %>'; ``` Instead, you can now drop the `.erb` extension and use r inline: ``` javascript var url = r(user_path, 42); ``` ## Tests You can run the test suite locally using the following commands: ``` bash $ gem install bundler $ cd /path/to/local/asset_pipeline_routes $ bundle install $ bundle exec rake spec ``` Whatever you do, make sure the tests stay green ;) # License Copyright © 2011-2013 Raphael Randschau <nicolai86@me.com> asset\_pipeline\_routes is distributed under an MIT-style license. See LICENSE for details.
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
asset_pipeline_routes-0.3.0 | README.md |