I am creating an application on which i just want to use all my app's routes should access via seo urls using slugs. i have created a slug field in my database table. this my migration file code
class AddSlugToClients < ActiveRecord::Migration
def change
add_column :clients, :slug, :string
end
end
i have added this code to my controller's show method my controller's code is:
def show
@client = Client.find_by_slug(params[:id])
end
In my app's model i have added this code class Client < ActiveRecord::Base
def slug
ename.downcase.gsub(" ", "-")
end
validates_presence_of :slug
def to_param
slug
end
end
now when i create a new client than client is created by the perfect slug. but when i click show link from the listing page to that clients then getting an error in url which looks like
clients/%23<Client::ActiveRecord_Relation:0xb59828d4>
now please help me to create a seo url for show page while clicking from index view
Aucun commentaire:
Enregistrer un commentaire