PLEASE NOTE, THIS PROJECT IS NO LONGER BEING MAINTAINED
Withardry
Gem provides shorcuts for ActiveRecord scopes and to_param method.
Getting Started
Prerequisites
Current version works with Rails 3.x only but old version is capable with Rails 2.x.
Installation
gem "withardry"
Usage
class Post < ActiveRecord::Base
withardry :title
# exactly same as
# scope :with_title, lambda { |t| where(:title => t) }
friendly_url
# same as to_param with model id and name attribute
friendly_url :title
# same as to_param with model id and title attribute
end
Now use this inside your app:
Post.with_title("Some title")
post = Post.create(:title => "Title Example")
post.to_param # => "1-title-example"
Sure, it can handle some options
class Post < ActiveRecord::Base
belongs_to :user
withardry :user, :prefix => "by", :as => "user_id"
// exactly same as
// scope :by_user, lambda {|u| where(:user_id => u) }
end
And then anywhere in your app
Post.by_user(some_user_id)
Contributing
Please read Code of Conduct and Contributing Guidelines for submitting pull requests to us.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Andrey Ognevsky - Initial work
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License.