Beautified Url Basic tool which provides feature of generating tokens which can be used in url for identifying resource(uniquely of uniquely within a scope) instead of :id. Just add another field which starts with _bu_ of one or many existing fields to make it all happen. Example: For a blog post, if you have a 'title' field and want to beautify and use it .
Simple way to implement ..
1. Adding gem in your Gem-file.
2. Now you have to create a migration(adding a column for _bu_ url ) on model for beautified Url.
the name of column is start with _bu_ .
3. Now last step is create routes for the resources
Simple way to implement ..
1. Adding gem in your Gem-file.
gem 'beautified_url', '~> 0.0.2'
2. Now you have to create a migration(adding a column for _bu_ url ) on model for beautified Url.
the name of column is start with _bu_ .
class AddingBfColumnInUsers < ActiveRecord::Migration
def change
add_column :users, :_bu_name, :string, after: 'full_name'
end
end
---------------------------------------------------------------
class AddingBfColumnInProjects < ActiveRecord::Migration
def change
add_column :projects, :_bu_name, :string, after: 'name'
end
end
3. Now last step is create routes for the resources
get ':_bu_full_name/:_bu_name', to: 'projects#show', as: :show_project
get ':_bu_full_name/:_bu_name/edit', to: 'projects#edit' , as: :edit_project
NOTE : If prams not found then You have also pass _bu_name and _full_name (user full name ) as prams through model by overriding to_prams default methods.
class Project < ActiveRecord::Base
def to_param
_bu_name.to_s
end
end
No comments:
Post a Comment