i redirecting city page as: <%= link_to @city.name, city_path(id: @city) %>
it's not right way since url being: localhost:3000/city?id=2
need url like: localhost:3000/newyork
did: <%= link_to @city.name, city_path(@city.name) %>
url is: http://localhost:3000/city.newyork
action city. url like:
localhost:3000/cityname
example:
localhost:3000/china
localhost:3000/pakistan
in gem file write
gem "friendly_id"
after writing gem in gemfile run bundle install
create migration add slugs column in model
rails g migration addslugtocity add_column :cities, :slug, :string add_index :cities, :slug, unique: true
in controller write
@city = city.friendly.find(params[:id])
in city module use friendly id
class city < activerecord::base extend friendlyid friendly_id :title, use: :slugged end
Comments
Post a Comment