Code Monkey home page Code Monkey logo

friendly_id's People

Contributors

aduffeck avatar alejandroperea avatar avokhmin avatar cllns avatar dgynn avatar empact avatar eric avatar ifesdjeen avatar jhawthorn avatar jhdavids8 avatar jjb avatar kamal avatar kimrgrey avatar miloops avatar myabc avatar nburkley avatar nono avatar norman avatar olivierlacan avatar padi avatar parndt avatar petergoldstein avatar pikachuexe avatar pixeltrix avatar seanabrahams avatar shioyama avatar slbug avatar technicalpickles avatar vfonic avatar xymbol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

friendly_id's Issues

custom slug method doesn't seem to be working

The old style of passing a block was working great for this, but I can't seem to get the new custom slug / method to work:

class Widget
  has_friendly_id :custom_slug, :use_slug => true, :scope => :group

  def custom_slug
    "n#{some_attr}"
  end
end

What's strange is that when I create a new instance, it works and gives me the correct value ("n1") but when the record is reloaded, it reverts to "1".

Permalink structure

Hi, all.
Maybe it will be better, if there will be possibility, to generate permalinks name like
id-permalink? For example http://sitename/users/1234-user. It will helps with non-unique slug names and with word reservations (nobody can use new/create/destroy/update - all REST words as ids).

Using friendly_id in an after_create filter

I'm not sure if this is a bug or not, but it has certainly thrown me for a loop. I'm using this code in an ActionMailer template:

<%= post_url( @post, :host => HOST ) %>

From the Post class:

class Prayer < ActiveRecord::Base
  has_friendly_id :title, :use_slug => true

If the title is 'My Post', the above renders the correct url everywhere in the app except for Mailers:

post_url( @post, :host => HOST ) # => http://myapp.com/posts/my-title
@post.to_param # => my-title

In mailer templates, I get this:

post_url( @post, :host => HOST ) # => http://myapp.com/posts/3
@post.to_param # => 3

Anything I need to do to make friendly_id work in a mailer template? Am I missing something?

-Ryan

rake redo_slugs MySql:Error

RAILS_ENV=production /opt/ruby-enterprise-1.8.6-20081215/bin/rake friendly_id:redo_slugs MODEL=Post
(in /var/www/cet.li/releases/20091210125359)
rake aborted!
Mysql::Error: Column 'created_at' in order clause is ambiguous: SELECT DISTINCT posts.id FROM posts LEFT OUTER JOIN slugs ON slugs.sluggable_id = posts.id AND slugs.sluggable_type = 'Post'WHERE (slugs.id IS NULL) ORDER BY created_at DESC LIMIT 100

Cached slugs come up with wrong sequence

DISCLAIMER: I'm also having the same problem as issue #14, and they could be related

However, when I do: rake friendly_id:redo_slugs MODEL=User all of the cached_slug columns come up with the wrong sequence (the sequence is one greater than it should be). I think this is happening because in the set_slug_cache method you're calling slug.to_friendly_id (line 127) which is auto-incrementing the sequence, because the slug has already been created.

Let me know if anyone else is experiencing the same thing -- I'll work on a patch and submit it if I have time!

Retry find with partial slug

I'm running into instances where some of our backlinks are getting chopped off or mangled due to user or program error, thus generating 404s. It would be great to have a feature to turn on partial slug finding.

Example One:

Example Two:

I hope to set some time aside soon to create a patch for this, but perhaps it's an easy add for you.

Thanks again for all the great work on Friendly ID.

Model.find fails when you pass it an ActiveRecord::Base instance (attempt to call private method)

Imagine code like this:

  Post.find(@post)

This fails with a stack like:

/gentoo/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/attribute_methods.rb:236:in `method_missing'
./test/../lib/friendly_id/slug.rb:44:in `parse'
./test/../lib/friendly_id/sluggable_class_methods.rb:16:in `find_one'

You might ask 'why' you'd do this, and I'd agree it's odd, but it does work without friendly_id. It is worth noting that Post.destroy(@post) uses these finder methods under the hood as well, and this is how I discovered it was a problem.

Order by Name?

Hi Norman, I'm having trouble listing objects by their names after I implement friendly_id. The default is that objects get listed by slug_id, but there is a name column in the slug table, and I'd like to order my objects by those names. Does friendly_id support this? Thanks for the great work on this!

rake friendly_id:make_slugs fails

rake friendly_id:make_slugs MODEL=Album

rake aborted!
Mysql::Error: Column 'name' in order clause is ambiguous: SELECT DISTINCT `albums`.id FROM `albums`  LEFT OUTER JOIN `slugs` ON `slugs`.sluggable_id = `albums`.id AND `slugs`.sluggable_type = 'Album'WHERE (slugs.id IS NULL)  ORDER BY name ASC LIMIT 100

Relevant configuration:
# name :string(255)
# cached_slug :string(255)
class Album < ActiveRecord::Base
has_friendly_id :name, :use_slug => true, :max_length => 50, :scope => :artist

Should require 'active_record'

In Rails 3 gems are loaded before Active Record, Action View, and the other frameworks so in order to not get this (or a similar) error:

/home/david/code/skoleportalen/vendor/gems/ruby/1.8/gems/friendly_id-2.2.7/lib/friendly_id/slug.rb:2: uninitialized constant ActiveRecord (NameError)

... FriendlyId should require 'active_record'.

No Slug and %20 instead of a space/dash.

Hi,

Is it normal that when you're not using the :use_slug => true option that you'll end up getting a %20 for every space in the attribute's value? When using the :use_slug => true option, this will be converted into "dashes". Since the attribute that I'm adding to the has_friendly_id method will always be unique I don't believe I need to use a slug, but it'd be nice to still get the "pretty url" with dashes instead of %20's.

Is this a bug? Or is there a particular reason you let it be a %20 rather than converting it to a dash?

Thanks!
Michael

Problem with caching slugs

While calling rake friendly_id:redo_slugs MODEL=Article ive got the message

rake aborted!
undefined method `friendly_id_options' for #Class:0x1a747ec

Any idea why this is happening? Ive tried to solve it but without success.

stack level too deep

I'm guessing this must have something to do with a conflicting plugin or something, but I'm getting a 'stack level too deep' error on a simple Model.find(id) call. Here's the short trace. Happy to provide a longer trace if you'd like it:

stack level too deep

/Users/josh/.gem/ruby/1.8/gems/friendly_id-2.1.4/lib/friendly_id/sluggable_class_methods.rb:21:in find_one_without_friendly' /Users/josh/.gem/ruby/1.8/gems/friendly_id-2.1.4/lib/friendly_id/sluggable_class_methods.rb:21:infind_one'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1574:in find_from_ids' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:616:infind'

Thanks!

Replacing "space" delimited with something else

I noticed that in the rdocs it says that spaces should be replaced with dashes "-" and not %20, which is what is the current behavoir.

How can I configure friendly_id to use something other than %20 for a space, such as using the "-" which I believe is better for seo purposes

Slugs are no longer used for finding a record with cached_slug column

The 2.3.0 release breaks resolving of old slugs when using a cache key. This problem also exists in the 2.3.1 release. First of all: thank you for using the cached_slug value in the standard find, it gives a nice performance improvement. On the downside: the change breaks looking up of old slugs from the table.

When using a model that has has_friendly_id :name, :use_slug => true and a cached_slug column, I presume that old values are still resolved.

Example:

>> m = Model.find('lorem-ipsum')
=> #<Model id: 903, name: "Lorem ipsum", cached_slug: 'lorem-ipsum'>
>> m.name = "dolor sit amet"
=> "dolor sit amet"
>> m.save
=> true
>> m.cached_slug
=> "dolor-sit-amet"

>> m = Model.find('lorem-ipsum')
ActiveRecord::RecordNotFound: ActiveRecord::RecordNotFound
>> m = Model.find('dolor-sit-amet')
=> #<Model id: 903, name: "dolor sit amet", cached_slug: "dolor-sit-amet">
>> m.slugs
=> [#<Slug id: 1365, name: "dolor-sit-amet", sluggable_id: 903, sequence: 1, sluggable_type: "Model", scope: nil, created_at: "2010-02-11 07:18:24">, #<Slug id: 144, name: "lorem-ipsum", sluggable_id: 903, sequence: 1, sluggable_type: "Model", scope: nil, created_at: "2009-12-09 08:36:15">]

There are Slug records for both slugs, but the table is never used for finding because there is a cached_slug column on that specific model.

Is it possible to do a (optional) second find query in the model when a search using the cached_slug throws a ActiveRecord::RecordNotFound exception?

changing a slug breaks children with scoped slugs?

I have nested resources in an application. For example, groups and widgets, with slugs via friendly_id for each. The friendly_id declaration for widget looks like:

has_friendly_id :name, :use_slug => true, :scope => :group

When I do Widget.find('widget-slug', :scope => 'group-slug') it works great and I get what I expect.

However, if the group name value changes and the slug gets updated, doing Widget.find('widget-slug', :scope => 'updated-slug') no longer manages to find the record.

If I take a look at Group.find(group_id).slugs, both the old slug and the new slug are present in the array. However, if I look at Widget.find(widget_id).slugs, I see only the older slug combo. It appears as if altering the parent never updates any children that might be relying on that parent scope.

Am I missing some extra step I need to take in order to make sure that dependent slugs are regenerated?

Thanks!

wrong friendly_id saved to cached_slug column

there is no sequence in friendly_id which is saved to cached_slug column.
problem in set_slug method, you aren't set sequence for new slug before saving it to cached_slug column.

Problem when try set days to remove old slugs

Hello,

I try run this command, rake friendly_id:remove_old_slugs MODEL=Product DAYS=100

And i get this error:

$ rake friendly_id:remove_old_slugs MODEL=Product DAYS=100
(in /Users/diegorv/rails/work/cms_test)
rake aborted!
uninitialized constant FriendlyId::Task

(See full trace by running task with --trace)

typo in post_install_message

I just noticed that the post_install_message for the gem isn't quite accurate. It says I should run

./script generate friendly_id --skip-migration

if I'm upgrading friendly_id. It should probably be

./script/generate friendly_id --skip-migration

script/generate friendly_id doesn't make sure lib/tasks exist

I was running the generator on a project I had cloned from git... and because git doesn't keep around empty directories, lib/tasks didn't exist. The generator failed because it was trying to copy friendly_id.rake into a directory that didn't exist yet.

To address this, the generator just needs to do m.directory "lib/tasks" before putting a file in there.

does strip_diacritics break in 2.3.0

Is this just me or does the latest gem release 2.3.0 break the option :strip_diacritics => true
It seems like it's now the default option but we have a lot of sites using that syntax so it would be good to know whether it's officially unsupported or is instead just a bug in 2.3.0

Running Rails 2.3.5 on OSX + UNIX both break.

Error message:
stack level too deep

Exception class:
SystemStackError

Relevant Backtrace:
0 /Library/Ruby/Gems/1.8/gems/friendly_id-2.3.0/lib/friendly_id/configuration.rb 117 in strip_diacritics=' 1 /Library/Ruby/Gems/1.8/gems/friendly_id-2.3.0/lib/friendly_id/configuration.rb 117 instrip_diacritics='
2 /Library/Ruby/Gems/1.8/gems/friendly_id-2.3.0/lib/friendly_id/configuration.rb 83 in send' 3 /Library/Ruby/Gems/1.8/gems/friendly_id-2.3.0/lib/friendly_id/configuration.rb 83 ininitialize'
4 /Library/Ruby/Gems/1.8/gems/friendly_id-2.3.0/lib/friendly_id/configuration.rb 82 in each' 5 /Library/Ruby/Gems/1.8/gems/friendly_id-2.3.0/lib/friendly_id/configuration.rb 82 ininitialize'
6 /Library/Ruby/Gems/1.8/gems/friendly_id-2.3.0/lib/friendly_id/active_record2.rb 16 in new' 7 /Library/Ruby/Gems/1.8/gems/friendly_id-2.3.0/lib/friendly_id/active_record2.rb 16 inhas_friendly_id'

Slug finder doesn't use cached_slug

I've my model setup with cached_slug column, but this column isn't used when I find the record by slug:

User.find(1)
User Load (0.1ms) SELECT * FROM users WHERE (users.id = 1)
=> #<User id: 1, name: "Ruben", created_at: "2010-01-19 21:45:40", updated_at: "2010-01-20 15:43:21", cached_slug: "ruben">

User.find('ruben')
User Load (0.1ms) SELECT users.* FROM users INNER JOIN slugs ON slugs.sluggable_id = users.id AND slugs.sluggable_type = 'User' WHERE (slugs.scope IS NULL AND slugs.sequence = '1' AND slugs.name = 'ruben') LIMIT 1
=> #<User id: 1, name: "Ruben", created_at: "2010-01-19 21:45:40", updated_at: "2010-01-20 15:43:21", cached_slug: "ruben">

attr_protected on cache_slugs

Hi,

friendly_id automatically makes a call to attr_protected on the cache column. This is a good thing except when the model uses attr_accessible. In that case, Rails blows up: "Declare either attr_protected or attr_accessible for YourModel, but not both."

Maybe friendly_id should let the developer disable this :
has_friendly_id :title, :protected => false

Slugs generated 2 times

When I launch rake friendly_id:make_slugs MODEL=MyModel :

  • terminal shows "model(n) friendly_id set to "slug-for-modeln"" for each line in the DB
  • but it records "slug-for-modeln" as sequence 1 AND "slug-for-modeln--2" as sequence 2

I also tried to generate the slugs with send(:set_slug) in the index controller and I get the same result.

This happens whether there is a cached_slug column or not.
When I create a new record, the slug is generated once only.

Optional validations

I'm using the latest friendly_id (2.3.0) on Rails 2.3.5. I have an Order model that has a "number" column. The number is populated immediately after creation because the value depends upon knowing the ID of the order. I want to use friendly_id on this column directly (no slug column) but my order creation dies with the following errors:

["Number can't be blank", "Number is too long (maximum is 255 characters)"]

Am I able to deactivate or conditionally skip these validations?

strip_diacritics fails if column is blank

This is such a small fix, so pasting it here:

Raises error:

The error occurred while evaluating nil.unpack

Fixed version:

    def strip_diacritics(string)
      ActiveSupport::Multibyte.proxy_class.new(string).normalize(:kd).unpack('U*').inject([]) { |a, u| 
        if ASCII_APPROXIMATIONS[u]
          a += ASCII_APPROXIMATIONS[u].unpack('U*')
        elsif (u < 0x300 || u > 0x036F)
          a << u
        end
        a
      }.pack('U*')
    rescue
      nil
    end

..which will instead lead to the somewhat nicer exception:

FriendlyId::SlugGenerationError (The slug text is blank.)

...which I believe one should be able to optinalyl skip by using this excellent addition (gets my vote, becuase these are just unnecessary errors IRL):

http://github.com/blythedunham/friendly_id/commit/21ae5137d1a45b4c198669e0b1c0f320b062fba8

Reserved words in sluggable models

"For sluggable models, if such a word is used, it will be treated the same as if that slug was already taken (numeric extension will be appended). Defaults to ["new", "index"]."
But when I try to create object with name 'new' I got an exception "The slug text is a reserved value" ??

to_param broken in test environment

A bunch of my tests broke after upgrading to 2.2.6 from 2.1.1.

model:

class Category < ActiveRecord::Base
  has_friendly_id :name, :use_slug => true, :strip_diacritics => true
  #...
end

route:

map.namespace :admin do |admin|
  admin.resources :categories
end

console:

app.admin_category_path Category.find("my-category")
"/admin/categories/my-category"

looks good. But then, in a test:

Test fails:

assert_redirected_to  admin_category_path(cat)

fails with error:

Expected response to be a redirect to http://test.host/admin/categories/1109641034 but was a redirect to http://test.host/admin/categories/my-category

Simpler test:

assert_equal cat.friendly_id, cat.to_param

fails with

<"my-category"> expected but was <"1109641034">.

Problem using friendly_id with cache-money

When I turn on cache-money I immediately get ActiveRecord::RecordNotFound on records I'm using friendly_id with. When requesting the same records using their int id, there are no problems.

Anyone else successfully using cache-money and friendly_id together?

Postgresql error when running friendly_id app on Heroku (app works fine on sqlite on localhost)

My app includes friendly_id. It runs just fine -- including all migrations -- on my Mac, where sqlite is my database but I never write or see SQL code or errors.

The first model to load in my migrations is the project model, which is also the first to get a friendly_id. Unless I comment out has_friendly_id in /models/project.rb, I get the following when I run heroku rake db:migrate --trace:

rake aborted!
PGError: ERROR: relation "projects" does not exist
: SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = 'projects'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:188:in log' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:490:inquery'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1054:in column_definitions' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:674:incolumns'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1220:in columns' /home/slugs/89776_f1cc265_88f3/mnt/.gems/gems/friendly_id-2.2.4/lib/friendly_id/sluggable_instance_methods.rb:8:inincluded'
/home/slugs/89776_f1cc265_88f3/mnt/.gems/gems/friendly_id-2.2.4/lib/friendly_id.rb:65:in include' /home/slugs/89776_f1cc265_88f3/mnt/.gems/gems/friendly_id-2.2.4/lib/friendly_id.rb:65:inhas_friendly_id'
/disk1/home/slugs/89776_f1cc265_88f3/mnt/app/models/project.rb:8
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:155:in require' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:262:inrequire_or_load'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:221:in depend_on' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:133:inrequire_dependency'
/usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:368:in load_application_classes' /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:367:ineach'
/usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:367:in load_application_classes' /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:365:ineach'
/usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:365:in load_application_classes' /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:185:inprocess'
/usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:112:in send' /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:112:inrun'
/disk1/home/slugs/89776_f1cc265_88f3/mnt/config/environment.rb:14
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require' /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in require' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:innew_constants_in'
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:in require' /usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/tasks/misc.rake:3 /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:incall'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in execute' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:ineach'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in execute' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:ininvoke_with_call_chain'
/usr/local/lib/ruby/1.8/monitor.rb:242:in synchronize' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:ininvoke_with_call_chain'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:607:in invoke_prerequisites' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:ineach'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in invoke_prerequisites' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:596:ininvoke_with_call_chain'
/usr/local/lib/ruby/1.8/monitor.rb:242:in synchronize' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:ininvoke_with_call_chain'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in invoke' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:ininvoke_task'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:ineach'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in top_level' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in top_level' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:inrun'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in standard_exception_handling' /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:inrun'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/local/bin/rake:19:in `load'
/usr/local/bin/rake:19
(in /disk1/home/slugs/89776_f1cc265_88f3/mnt)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment

Friendly ID without slug versioning

Hello Norman,
we're having some problem utilizing friendly_id.

Let me explain our use case - we want to use friendly_id, but without the versioning features. Actually, we want to create a slug for a record only once, and be able to prevent it changing, even if the base for the slug (the title) changes.

So something in the lines of:

content = Content.create :title => 'Some title'
content.slug # => 'some-title'

content.title = 'New title'
content.save
content.slug # => 'some-title'

Is there a way we can do this with the current version of friendly_id, or do we need to modify it?

I'm aware that we can access the first slug with
content.slugs.last

But to_param doesn't work as expected, and I'm under the impression that slug caching (which we need to use because of the reduced performance hit) would fall apart.

Thanks in advance.

Best Regards,
Tomislav

Problems with custom tablenames

If a different table name is defined using "self.table_name = tablename_with_namespace" the latest version of friendly_id wont honor it ending up with

"Mysql::Error: Table 'project_development.tablename' doesn't exist"

Using 2.1.1 everything works fine.

Automagic detection of cached_slugs is broken

Hi,

with the last version of friendly_id (2.2.4), it seems that the automagic detection of the cached_slug column is broken. When I try to rebuild slugs on a model News with a cached_slug column and has_friendly_id :title, I obtain this message:

Class 'News' doesn't use slugs

Security question

Hi,
could you tell me plz - what is the best way to restrict access to slug creation - for example - only admins can create new slugs, but others can use it?

Scope doesn't update when underlying record is changed

Sorry for another issue...

When you have a scoped slug, and the name of the scope changes, the slugs are not updated. i.e. I have users and posts, and there's the option :scope => :user. When I change the friendly_id of the user (which is name), the scope of the posts is not updated, and therefore they cannot be found by the find_one method (which is looking for an item with the new scope)

Let me know if you need a more concrete example. Thanks for the help with this awesome gem!

Datamapper support?

I must say this is an awesome slug based URL plugin. I could not find anything else comparable to this.

However, I'm currently using datamapper for my project. And I would love it if this would also work with datamapper too.

Thank you!

Scope using custom method

Not sure if this one is a bug or a just me doing it wrong,
I'm trying to define a scope using a custom method, I didn't find any examples in the doc, so I just tried like that :

class User < ActiveRecord::Base
  has_friendly_id :name, :use_slug => true, :scope => :toto

  def toto
    "toto"
  end 
end 

I thought this will return urls like /users/toto/name-of-the-user

But I always have the url : /users/name-of-the-user
and the error : ActiveRecord::RecordNotFound; expected scope but got none

Am I doing something wrong ?

Thanks,
Mike
I am missing something ?

Active support dependency problem

Version 2.3.5 is currently unable to resolve an active support dependency for me.

/Library/Ruby/Gems/1.8/gems/friendly_id-2.3.2/lib/friendly_id/slug_string.rb:24: uninitialized constant FriendlyId::ActiveSupport (NameError)
from /Library/Ruby/Gems/1.8/gems/friendly_id-2.3.2/lib/friendly_id.rb:1:in require' from /Library/Ruby/Gems/1.8/gems/friendly_id-2.3.2/lib/friendly_id.rb:1 from /Library/Ruby/Gems/1.8/gems/bundler-0.9.8/lib/bundler/runtime.rb:41:inrequire'
from /Library/Ruby/Gems/1.8/gems/bundler-0.9.8/lib/bundler/runtime.rb:41:in require' from /Library/Ruby/Gems/1.8/gems/bundler-0.9.8/lib/bundler/runtime.rb:36:ineach'
from /Library/Ruby/Gems/1.8/gems/bundler-0.9.8/lib/bundler/runtime.rb:36:in require' from /Library/Ruby/Gems/1.8/gems/bundler-0.9.8/lib/bundler/runtime.rb:35:ineach'
from /Library/Ruby/Gems/1.8/gems/bundler-0.9.8/lib/bundler/runtime.rb:35:in require' from /Library/Ruby/Gems/1.8/gems/bundler-0.9.8/lib/bundler.rb:71:inrequire'
from test.rb:17

Any ideas? Thanks.

It doesn't work with mysql 5.0.51

I was developing with sqlite3 and everything worked find, but now I tried my first deployment to mysql and I get the following error message:

Mysql::Error: Specified key was too long; max key length is 1000 bytes: CREATE UNIQUE INDEX `index_slugs_on_n_s_s_and_s` ON `slugs` (`name`, `sluggable_type`, `sequence`, `scope`)

Russian tests

Hi, i've tested your plugin with slugs in Russian and can confirm, that it works fine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.