问题标签 [friendly-id]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1136 浏览

ruby-on-rails-3 - Ruby on Rails 生成路由

我正在尝试在我的 rails 应用程序中生成路线。该应用程序具有电影表和列类型。我想制作这样的路线:/movies-genre-horror 并显示所有具有流派恐怖的电影。真的有可能吗?如果是,任何人都可以提示如何做到这一点?如果有教程可以做到这一点,我会很好。我确实是这样制作的:/movies/genre/horror 并且它有效。我使用 gem friendly_id 并使用 slug 来更改对 url 不友好的类型。

0 投票
1 回答
137 浏览

ruby-on-rails-3 - FriendlyId 建议

我想使用 FriendlyId 来实现这一点localhost3000/users/edu/profile,但我不知道该怎么做!我有这些模型 User 和 UserProfile

如何加载UserProfilename的用户?name以及当 UserProfile 的名称更改时如何更新用户的名称?

我第一次使用

但是当我在 UserProfile 中更新或创建新的配置文件时,我无法更改它。

使用 Ruby 1.9.3 和 Rails 3.2.13。

0 投票
1 回答
625 浏览

ruby-on-rails - 带有 URL 内的 URL 的 Rails FriendlyId

我的应用缓存网页

在 pages#new 上,当您提交 URL(不带http://前缀)时,会创建一个页面并将您重定向到节目,例如pages/4ID 为 4

我正在尝试添加friendly_id,但在添加到我的之后遇到extend FriendlyIdfriendly_id :url问题Page问题

如果我提供“yahoo.com”,重定向会转到 page/yahoo.com。yahoo.com 被解释为{"id"=>"yahoo", "format"=>"com"}Rails 告诉我Couldn't find Page with id=yahoo

如果我提供“yahoo.com/index.html”,重定向会转到 page/yahoo.com/index.html 但我只是得到No route matches [GET] "/pages/yahoo.com/index.html"

你觉得我能怎么解决这个问题?

0 投票
1 回答
216 浏览

ruby-on-rails - 带有智能重定向的 StackOverflow 样式路由

StackOverflow 似乎有这种风格的问题路线:

这很容易实现,无论是在路线上还是在to_param.

但是,当仅传递一个 ID 时,StackOverflow 似乎也会重定向到该路径。

例子:

重定向到:

蛞蝓的任何变化也是如此

仍将重定向到相同的 URL。

我的问题是:这种类型的重定向通常在控制器中处理(将请求与路由进行比较)还是有办法做到这一点routes.rb

我认为routes.rb文件中不可能发生这种情况的原因是,通常您无权访问该对象(因此您无法根据 ID 获取 slug,对吗?)

对于任何感兴趣的人,Rails 3.2.13 并使用FriendlyID

0 投票
0 回答
293 浏览

ruby-on-rails - 猴子在 Rails 3 中修补 Gem 方法

我愿意将friendly_id gem 与Firebird 一起使用,但我需要使用与Firebird 相关的代码来覆盖实现特定SQL 函数的方法。

我创建了config/initializers/friendly_id_monkey_patch.rb包含以下代码的文件:

然而,应用程序继续执行原始 gem 的方法,忽略了我的补丁。有什么问题?

0 投票
2 回答
1120 浏览

ruby-on-rails - FriendlyID 韩国蛞蝓

当我添加带有标题的韩语文章时,例如:신품

FriendlyID gem 创建空白 slug 和 url 就像/8......所以这是 ID。看看这个链接:http://www.srecipe.kr.com/articles/8

其他语言工作。

如何从 /this-is-url 获取映射到拉丁字母的 url 신품

0 投票
2 回答
419 浏览

ruby-on-rails - Rails 友好的 id 句号

我正在使用 Friendly id 来允许在我的 Rails 应用程序中从用户名进行自定义查询。

所以说用户的用户名是loremipsum

rails 会显示这个http://localhost:3000/users/loremipsum,这工作得很好

但说用户的用户名是lorem.ipsumlorem-ipsum

我怎样才能让rails显示,lorem.ipsum或者lorem-ipsum在url中,因为它目前需要第一部分,然后说Couldn't find User with id=lorem

我的用户控制器

0 投票
1 回答
158 浏览

ruby-on-rails - 使用 belongs_to/has_many 关联时未定义的方法“event_id”

我正在创建一个有事件的网站。每个事件都充当画廊和has_many图像。每个图像belongs_to和事件。

我关注了RailsCast #253 CarrierWave gem。当我尝试添加新图像时,它说

# Image:0x7302438 的未定义方法“event_id”

<%= form_for @image, :html => {:multipart => true} do |f| %>

<%= f.error_messages %>

<%= f.hidden_field :event_id %>

<%= f.label :title %><br />

<%= f.text_field :title %>

这是我的 image.rb

class Image < ActiveRecord::Base

attr_accessible :event_id, :title, :image

validates :title, :image, :presence => :true, :uniqueness => :true

belongs_to :event

mount_uploader :image, ImageUploader

end

和 event.rb

class Event < ActiveRecord::Base

attr_accessible :title, :date, :about

validates :title, :about, :date, :presence => :true

validates :title, :uniqueness => :true

has_many :images

extend FriendlyId

friendly_id :title, use: [:slugged, :history]

end

0 投票
2 回答
301 浏览

ruby-on-rails - Translate FriendlyID slugs to a corresponding ID

I have a comments scaffold and a movies scaffold.

Users can comment on movie in this path /movies/the-social-network/comments/new

My issue is that the comments use movie_id to work and to link with the movies.

So what I'm asking is how to pass the-social-network as the movie_id?

PS: Im using Friendly Id 4

0 投票
1 回答
433 浏览

ruby-on-rails - FriendlyId 不添加序列并抛出 ActiveRecord::RecordNotUnique

上下文非常简单,我有一个从 FriendlyId 扩展的 Course 模型,如下所示:

如果我创建具有相同类型、名称、城市和结构的课程,我会收到以下错误:

我不明白为什么 FriendlyId 不在 slug 末尾添加序列号......欢迎任何建议。

我试图在friendly_name 方法中返回一个字符串而不是一个数组,但错误仍然存​​在。

编辑

删除 :history 解决了这个问题。

我也尝试过 FriendlyId 的其他分支(4.0-stable、4.1.x),但它不能解决问题。