friendly-id

Troubleshooting friendly_id w/ Rails 4: working as expected in rails console, getting RecordNotFound error from controller

本秂侑毒 提交于 2019-12-11 02:54:17
问题 I've been successfully using friendly_id with multiple models in my Rails 4 app. I previously had two models that I've decided to combine (Terminals and Locations). The Terminals show action was previously working with friendly_id, where I could visit /terminals/albany and get the Terminal with the slug 'albany'. I've gone through the bulk of the refactor to condense down to just Locations, and am on the last piece (fixing views). Along the way I've been testing things in Rails Console and

Friendly ID slug does not contain the id

和自甴很熟 提交于 2019-12-10 10:36:35
问题 I want to have urls like this: http://domain.com/products/454-table-lamp So I use friendly_id like so: extend FriendlyId friendly_id :slug_candidates, use: :history def slug_candidates [ [:id, :title] ] end Now, since friendly id generates the slug before the object is saved I end up with an url like so (Please note the missing id in the URL): http://domain.com/products/table-lamp Now while this is not too bad as such. As soon as I save another Product called "Table Lamp", I will get an URL

Friendly ID 4 Using scoped module

狂风中的少年 提交于 2019-12-10 10:05:57
问题 I can't work this out. Using the documentation I have two models class Region < ActiveRecord::Base extend FriendlyId has_many :pages friendly_id :name, :use => :slugged end class Page < ActiveRecord::Base extend FriendlyId belongs_to :region friendly_id :name, :use => :scoped, :scope => :region end According to the documentation this should work. But when I create a page it's not creating a slug via a scope, and this means when I create another page with the same name I get duplicate index

NoMethodError at / undefined method `name' for nil:NilClass

耗尽温柔 提交于 2019-12-08 11:09:27
问题 I have tried many solution and came up with good one but still getting error. I am editing my whole question. I am trying to create Friendly URL with friendly_id gem. In my project First user need to signup with devise. Devise will pass some information to profile model with model/user.rb delegate :age, :city, :region, :country, to: :profile I want to make user.name to be Friendly_id candidate. I have tried following code in my Profile model:- class Profile < ActiveRecord::Base extend

User editable slugs with Friendly ID

蹲街弑〆低调 提交于 2019-12-07 03:27:30
问题 Case: My station forms contain a slug field, if a value is entered it should be used as the slug. EDIT: some clarification: What I want is much like how slugs work in wordpress: If no slug is provided -> slug the name If slug is provided -> use the user entered slug If slug is updated -> push old slug to history My problem: Can´t figure out how to get Friendly Id to use the user provided slug. class Station < ActiveRecord::Base extend FriendlyId belongs_to :user has_many :measures validates

Redirect same page to different language with Globalize & Friendly_id

三世轮回 提交于 2019-12-07 01:07:10
问题 I've been scratching my head for the last few hours, looking for an answer but I can't find it anywhere. My gem file: # Use globalize for translating models gem "globalize", github: "ncri/globalize" # for Rails 4.2 gem 'globalize-accessors', '~> 0.1.5' # Use friendly_id for slugs gem 'friendly_id', '~> 5.1.0' gem 'friendly_id-globalize', '~> 1.0.0.alpha1' Here's the situation: I have two languages "en" and "fr" 2 models : pages and pages_translations pages has a slug column, pages

How can I use friendly ID in Rails like mysite.com/[USERNAME]

半世苍凉 提交于 2019-12-06 02:44:21
问题 How can I use friendly URLs on my Rails application ? All I need is to make available the following url format mysite.com/company1 mysite.com/user123 mysite.com/user1234 mysite.com/newton.garcia mysite.com/company-name Can anyone help ? 回答1: I already ask this question on Quora.. http://www.quora.com/How-does-Quora-rewrite-their-urls For who really interested to implement Quora/Facebook URLs like. Heres a tip in Rails3: Make a table called slugs : # slug | model_id | model # =================

Friendly ID 4 Using scoped module

筅森魡賤 提交于 2019-12-05 18:30:02
I can't work this out. Using the documentation I have two models class Region < ActiveRecord::Base extend FriendlyId has_many :pages friendly_id :name, :use => :slugged end class Page < ActiveRecord::Base extend FriendlyId belongs_to :region friendly_id :name, :use => :scoped, :scope => :region end According to the documentation this should work. But when I create a page it's not creating a slug via a scope, and this means when I create another page with the same name I get duplicate index error. If you are currently indexing your pages on the slug field with something like this: add_index

Friendly ID slug does not contain the id

丶灬走出姿态 提交于 2019-12-05 18:27:27
I want to have urls like this: http://domain.com/products/454-table-lamp So I use friendly_id like so: extend FriendlyId friendly_id :slug_candidates, use: :history def slug_candidates [ [:id, :title] ] end Now, since friendly id generates the slug before the object is saved I end up with an url like so (Please note the missing id in the URL): http://domain.com/products/table-lamp Now while this is not too bad as such. As soon as I save another Product called "Table Lamp", I will get an URL like this: http://domain.com/products/table-lamp-ebaf4bf5-a6fb-4824-9a07-bdda34f56973 So my question is,

User editable slugs with Friendly ID

不羁的心 提交于 2019-12-05 06:52:12
Case: My station forms contain a slug field, if a value is entered it should be used as the slug. EDIT: some clarification: What I want is much like how slugs work in wordpress: If no slug is provided -> slug the name If slug is provided -> use the user entered slug If slug is updated -> push old slug to history My problem: Can´t figure out how to get Friendly Id to use the user provided slug. class Station < ActiveRecord::Base extend FriendlyId belongs_to :user has_many :measures validates_uniqueness_of :hw_id validates_presence_of :hw_id class_attribute :zone_class self.zone_class ||=