routing - Rails + Using Friendly ID for slug generation and creating trouble while accessing from DB -


facing strange problem respect slug in rails

loading development environment (rails 3.2.13) 2.1.2 :001 > tutorial.last   tutorial load (0.7ms)  select "tutorials".* "tutorials"    order "tutorials"."id" desc limit 1   => #<tutorial id: 3, title: "populating database’s seeds.rb",     state: "publish", content_introduction: "<p>demo data</p>\r\n",      slug: "populating-the-database-s-with-seeds-rb">   2.1.2 :002 > tutorial.last.slug   tutorial load (0.6ms)  select "tutorials".* "tutorials"      order "tutorials"."id" desc limit 1  => "populating-the-database’s-with-seeds.rb"  

in database show "-" replacing special character while accessing gives it.

model

def slug   title.strip.downcase.gsub(/[:,'"%^&*+=<>.`~]/,"").gsub("’","").gsub("  ", " ").gsub(" ", "-") end  def to_param   "#{slug}".parameterize end  extend friendlyid friendly_id :title, use: [ :slugged, :history ]    

so while accessing page using slug gives error. please have , suggest something.

there difference between see value of slug in tutorial.last , in tutorial.last.slug

tutorial.last fetches last record table giving slug saved in database, tutorial.last.slug calling slug method defined in model, tutorial.last object , using object calling slug method

def slug   title.strip.downcase.gsub(/[:,'"%^&*+=<>.`~]/,"").gsub("’","").gsub("  ", " ").gsub(" ", "-") end 

so comment out above method , same results in both cases!

looks slug method have defined in model manipulating title field slug value, far know friendly_id gem handles it, comment out slug method. solve problem. hope helps!


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -