如何摆脱下划线" _"从rails生成的url?

时间:2017-04-20 10:02:20

标签: ruby-on-rails actioncontroller

我刚刚在rails app的类别模型上实现了 friendly_id 。之前它曾用于生成这样的URL:

localhost:3000/search?category_id=metal-processing-and-machine-tool 。现在我得到了生成url,如下所示

<a href="<%= search_equipments_path(:category_id => category.slug ) %>">

网址生成线是:

search_equipments

def search_equipments begin if (params.keys & ['category_id', 'sub_category', 'manufacturer', 'country', 'state', 'keyword']).present? if params[:category_id].present? @category = Category.active.find params[:category_id] else @category = Category.active.find params[:sub_category] if params[:sub_category].present? end @root_categories = Category.active.roots @sub_categories = @category.children.active if params[:category_id].present? @sub_categories ||= {} @countries = Country.active.all @manufacturers = Manufacturer.active.all @states = State.active.where("country_id = ?", params[:country]) if params[:country].present? @states ||= {} unless params[:category_id].present? && params[:sub_category].present? params[:category_id] = @category.id if params[:category_id].present? params[:sub_category] = @category.id if params[:sub_category].present? end @equipments = Equipment.active.filter(params.slice(:manufacturer, :country, :state, :category_id, :sub_category, :keyword)).order("#{sort_column} #{sort_direction}, created_at desc") else redirect_to root_path end rescue Exception => e redirect_to root_path, :notice => "Something went wrong!" end end 方法如下:

_

由于搜索引擎优化的原因,我上面的人告诉我要从网址category_id中删除{{1}}。我尝试通过更改url生成行中的格式。没有帮助。可以请任何人告诉我它是否可行,我该如何实现?

如果需要任何额外信息,请在评论中告诉我。

0 个答案:

没有答案