ruby on rails - Friendly id don't change slug in url -
i use friendly_id gem making slugs , globalize gem translations in rails when go show.html.erb , change language controller can't find entry. files are:
category.rb model:
# == schema information # # table name: categories # # id :integer not null, primary key # name :string # description :text # slug :string # created_at :datetime not null # updated_at :datetime not null # class category < activerecord::base validates_presence_of :name translates :name, :description, :slug extend friendlyid friendly_id :name, :use => [:slugged, :globalize] def should_generate_new_friendly_id? name_changed? end has_and_belongs_to_many :sponsors def name_with_initial "#{name}" end end
categories_controller.rb (only part try find category):
... private def set_category @category = category.friendly.find(params[:id]) rescue flash[:alert] = "category don't exist." redirect_to admin_categories_path end ...
when change locales on index.html.erb normal , see translations when i'm on show.html.erb page , change locales problems. make first en translation (default) , cz translation. when got to: http://localhost:3000/en/admin/categories/name-eng
than change cz link looks like: http://localhost:3000/cz/admin/categories/name-eng
only locales changed not slug , there no errors.
--- problem --- when go first cz variant link: http://localhost:3000/cz/admin/categories/name-cz
and try change en error. controller can't find because try find cz slug.
in console when change i18n slugs present.
do know why happening , how fix it? thank you!
--- edit --- works when change
@category = category.find(params[:id])
and link show.html.erb looks this:
<%= link_to category.name, admin_category_path(:id => category.id) %>
but can't have te friendly id.
Comments
Post a Comment