Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
formatted comments
  • Loading branch information
aashish committed Mar 14, 2018
commit 0574f92211787702e0c902afb1bc097acf4a8257
12 changes: 4 additions & 8 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,10 @@ In order to use the generated url attribute, you will probably want to override

Routing called via named routes like <tt>foo_path(@foo)</tt> will automatically use the url. In your controllers you will need to call <tt>Foo.find_by_url(params[:id])</tt> instead of the regular find. Don't look for <tt>params[:url]</tt> unless you set it explicitly in the routing, <tt>to_param</tt> will generate <tt>params[:id]</tt>.

Note that if you add <tt>acts_as_url</tt> to an existing model, the <tt>url</tt>
database column will initially be blank. To set this column for your existing
instances, you can use the <tt>initialize_urls</tt> method. So if your class is
<tt>Post</tt>, just say <tt>Post.initialize_urls</tt>.

To update the existing <tt>url</tt> database column which has data, you can use
<tt>reinitialize_urls</tt> method. So if your class is <tt>Post</tt>, just say <
tt>Post.reinitialize_urls</tt>.
Note that if you add <tt>acts_as_url</tt> to an existing model, the <tt>url</tt> database column will initially be blank.
To set this column for your existing instances, you can use the <tt>initialize_urls</tt> method. So if your class is <tt>Post</tt>, just say <tt>Post.initialize_urls</tt>.

To update the existing <tt>url</tt> database column which has data, you can use <tt>reinitialize_urls</tt> method. So if your class is <tt>Post</tt>, just say <tt>Post.reinitialize_urls</tt>.

Unlike other permalink solutions, ActsAsUrl doesn't rely on Iconv (which is inconsistent across platforms and doesn't provide great transliteration as is) but instead uses a transliteration scheme (see the code for Unidecoder) which produces much better results for Unicode characters. It also mixes in some custom helpers to translate common characters into a more URI-friendly format rather than just dump them completely. Examples:

Expand Down
15 changes: 6 additions & 9 deletions lib/stringex/acts_as_url.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: UTF-8
require "stringex/acts_as_url/adapter"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing magic comment # frozen_string_literal: true.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing magic comment # frozen_string_literal: true.

require 'stringex/acts_as_url/adapter'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.


module Stringex
module ActsAsUrl # :nodoc:
Expand Down Expand Up @@ -61,9 +61,7 @@ class << self

define_method :acts_as_url_configuration do
klass = self.class
while klass.acts_as_url_configuration.nil?
klass = klass.superclass
end
klass = klass.superclass while klass.acts_as_url_configuration.nil?
klass.acts_as_url_configuration
end
end
Expand All @@ -74,7 +72,6 @@ class << self
acts_as_url_configuration.adapter.create_callbacks! self
end


# Some ORMs function as mixins not base classes and need to have a hook to reinclude
# and re-extend ActsAsUrl methods
def included(base = nil, &block)
Expand All @@ -97,9 +94,9 @@ def initialize_urls
acts_as_url_configuration.adapter.initialize_urls! self
end

# Renitialize the url fields for the all records. Designed for people who want to update
# <tt>acts_as_url</tt> support once there's already development/production data they'd
# like to keep around.
# Renitialize the url fields for the all records. Designed for people who
# want to update <tt>acts_as_url</tt> support once there's already
# development/production data they'd like to keep around.
def reinitialize_urls
acts_as_url_configuration.adapter.reinitialize_urls! self
end
Expand Down