From cf992ff338bb512fb1099bf9290001794378af57 Mon Sep 17 00:00:00 2001 From: Toru KAWAMURA Date: Fri, 30 Nov 2012 07:52:28 +0900 Subject: [PATCH] Write example --- README.md | 46 +++++++++++++++++++++++++++++++----- resources_id_replace.gemspec | 4 ++-- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8dc4fbc..ac70a56 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,44 @@ -# ResourcesIdReplace +# resources_id_replace + +Replace param name of resources' id. +Useful for making user friendly URL. + +## Example + +You can use `:replace_id_with` option for `resources`. + +```ruby +resources :users, :replace_id_with => 'name' +``` + +``` + users GET /users(.:format) users#index + POST /users(.:format) users#create + new_user GET /users/new(.:format) users#new +edit_user GET /users/:name/edit(.:format) users#edit + user GET /users/:name(.:format) users#show + PUT /users/:name(.:format) users#update + DELETE /users/:name(.:format) users#destroy +``` + +Good with the following codes. + +```ruby +class User < ActiveRecord::Base + def to_param + name + end +end +``` + +```ruby +class UsersController < ApplicationController + def show + @user = User.find_by_name!(params[:name]) + end +end +``` -TODO: Write a gem description ## Installation @@ -16,10 +54,6 @@ Or install it yourself as: $ gem install resources_id_replace -## Usage - -TODO: Write usage instructions here - ## Contributing 1. Fork it diff --git a/resources_id_replace.gemspec b/resources_id_replace.gemspec index 46c5743..8c813f5 100644 --- a/resources_id_replace.gemspec +++ b/resources_id_replace.gemspec @@ -8,8 +8,8 @@ Gem::Specification.new do |gem| gem.version = ResourcesIdReplace::VERSION gem.authors = ["Toru KAWAMURA"] gem.email = ["tkawa@4bit.net"] - gem.description = %q{Replace path name of resources' id} - gem.summary = %q{Replace path name of resources' id} + gem.description = %q{Replace param name of resources' id} + gem.summary = %q{Replace param name of resources' id} gem.homepage = "https://github.com/tkawa/resources_id_replace" gem.files = `git ls-files`.split($/)