Project

withardry

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A simple plugin to DRY models
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

PLEASE NOTE, THIS PROJECT IS NO LONGER BEING MAINTAINED

Withardry

Gem provides shorcuts for ActiveRecord scopes and to_param method.

Sponsored by Evrone

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

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License.