Tag: friendly id

“key(slug)=()已经存在”在rails4 app上的friendly_id中

虽然我正在尝试将friendly_id设置为我的rails4项目,但同样地 ,我在“朋友”之后将“朋友”添加到friends表后出错。 我该如何解决它: PG::UniqueViolation – ERROR: duplicate key value violates unique constraint “index_friends_on_slug” DETAIL: Key (slug)=() already exists. 另外,以下是我的文件问题可能基于: # app/models/friend.rb: class Friend < ActiveRecord::Base has_many :entries, dependent: :destroy belongs_to :user extend FriendlyId friendly_id :candidates, use: [:slugged, :finders] # not :history here def candidates [ :first_name, [:first_name, :last_name] ] end end # db/schema.rb: create_table "friends", […]

FriendlyID不构建HTML转义slu

我有正确的friendly_id设置,一切正常,使用slugs。 我遇到的问题是我的Tag模型上的一些名称(这是FriendlyId附加到的模型)需要进行HTML转义。 名称如c++或.net 。 当我运行Tag.find_each(:&save) ,它为我生成了所有的Tag.find_each(:&save) ….但是在那些带有这些名称的标签上,这就是发生的事情: > c = Tag.where(:name => “c++”) Tag Load (0.9ms) SELECT “tags”.* FROM “tags” WHERE “tags”.”name” = ‘c++’ => [#] > Tag.where(:name => “.net”) Tag Load (0.9ms) SELECT “tags”.* FROM “tags” WHERE “tags”.”name” = ‘.net’ => [#] 1.9.3p392 :012 > Tag.where(:name => “c#”) Tag Load (1.0ms) SELECT “tags”.* FROM […]

如何将旧url重定向到rails app中新的friendly_id生成的url?

我使用friendy_id来friendy_id我的url。 我使用的旧url如下所示: localhost:3000/search?category_id=208 现在它看起来像这样: localhost:3000/search?category_id=metal-processing-and-machine-tool 我的控制器是这样的: def search_equipments begin if (params.keys & [‘category_id’, ‘sub_category’, ‘manufacturer’, ‘country’, ‘state’, ‘keyword’]).present? if params[:category_id].present? @category = Category.active.friendly.find_by_friendly_id params[:category_id] else @category = Category.active.friendly.find_by_friendly_id 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]) […]

slu col候选人铁路4

我的rails应用程序中有Job模型和Location模型。 我使用postgresql作为数据库。所以我在我的工作模型中将location_ids作为数组字段用于保存位置。 我在我的应用程序中使用FeriendlyId使我的url友好。 当我去我的工作秀页面我得到这个友好的url http://localhost:3000/jobs/seo-trainee 但现在我还想在我的url中包含作业所在的位置,就像这样 http://localhost:3000/jobs/seo-trainee-mumbai-tokyo 我知道我们可以为此目的使用slug_candidates。 但我不知道我怎么能完全实现这一点 目前我在我的工作模型中有这个 extend FriendlyId friendly_id :slug_candidates, use: [:slugged, :finders] def slug_candidates [ :title, [:title, :id] ] end

为什么我在使用friendly_id时不能再编辑和销毁我的引脚?

我相信我从friendly_id github页面正确地遵循了所有步骤。 我知道它有效,因为它将我的URL从/ 1更改为/ sample-url。 然而,问题是我无法编辑和销毁我已更改url的引脚。 我希望有人可以帮我解决这个问题。 谢谢! /pins_controller.rb class PinsController params[:page], :per_page => 8) respond_with(@pins) end def show respond_with(@pin) end def new @pin = current_user.pins.build respond_with(@pin) end def edit end def create @pin = current_user.pins.build(pin_params) if @pin.save redirect_to @pin, notice: “Pin was successfully created.” else render action: “new” end end def update if @pin.update(pin_params) […]

故障排除friendly_id w / Rails 4:在rails控制台中按预期工作,从控制器获取RecordNotFound错误

我已经成功地在我的Rails 4应用程序中使用了带有多个模型的friendly_id。 我之前有两个我决定合并的模型(终端和位置)。 终端显示行动以前使用的是friendly_id,在那里我可以访问/终端/奥尔巴尼并使用slug’albany’获得终端。 我已经通过大部分重构压缩到只有Locations,并且在最后一块(修复视图)。 一路上我一直在Rails控制台中测试并使用rspec,事情似乎按预期工作。 还有其他模型仍然可以按预期工作。 现在我正在为Locations的新显示页面工作,我在尝试访问/ locations / albany时遇到以下错误: ActiveRecord::RecordNotFound in LocationsController#show Couldn’t find Location with id=albany 但是,当我访问/ locations / 5时,它成功加载了记录。 它也适用于Rails控制台: Location.find(5) # returns the correct location object Location.find(5).slug # returns ‘albany’ Location.friendly.find(‘albany’) # returns the correct location object 当我查看Rails dbconsole中生成的slugs时,它们看起来都是正确生成的并且没有重复项。 这是我的模特: Class Location < ActiveRecord::Base extend FriendlyId friendly_id :slug_candidates, use: [:slugged, […]

友好的Id定制S ..

我有一个Post模型 #post.rb extend FriendlyId friendly_id :slug_candidates, use: [:slugged, :history] 我正在尝试为每个post自定义url #post.rb def slug_candidates “#tutorial-#{user.display_name}-#{title}” end 友好ID持续生成UUID slug,而我希望它生成一个全面的URL 通常我得到\ tutorial-john-49c9938b-ece5-4175-a4a4-0bb2b0f26a27而不是\ tutorial-john-some-comprehensive-title 谢谢

Rails friendly_id页面仍可通过记录ID获得

我在我的rails应用程序中使用了friendly_id gem,以创建漂亮干净的URL。 它运作良好,但页面也可通过te记录ID获得。 例: 我有一个’name’作为slug的记录。 此记录的ID为1。 所以页面可以从2个url获得: domain.com/name 和 domain.com/1 我只想使用domain.com/name,所以我不希望从domain.com/1获得该页面。 有谁知道怎么做到这一点?

没有Id:Rails 4自定义控制器动作,找不到

我正在尝试为某些数据创建一个JSON提要,以便将其部署到我所拥有的图形中。 我一直遇到“找不到没有Id的大坝”,而且没有任何关于SO的答案似乎都有解决方法。 我的参数似乎正在通过罚款,我有点困惑。 的routes.rb require “resque/server” Rails.application.routes.draw do mount Resque::Server, :at => “/resque” root ‘home#index’ get ‘about’, to: ‘home#about’ resources :dams, only: [:index, :show] do get ‘count_data’, to: ‘dams#count_data’ resources :fish_counts, only: [:index, :show] end resources :fish end dams_controller.rb中的自定义操作: def count_data @dam = Dam.includes(:fish_counts, :fish).friendly.find(params[:id]) @fish_counts = FishCount.for_year(Date.today.year).where(“dam_id =?”, @dam.id).limit(200).order(count_date: :desc) respond_to do |format| format.json […]

友好ID 4使用范围模块

我无法解决这个问题。 使用文档 我有两个型号 class Region :slugged end class Page :scoped, :scope => :region end 根据文档,这应该工作。 但是当我创建一个页面时,它不会通过作用域创建一个slug,这意味着当我创建另一个具有相同名称的页面时,我会得到重复的索引错误。