Forum: Ruby on Rails Routing issues with special characters

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Serengeti (Guest)
on 2007-06-29 21:32
(Received via mailing list)
I am using acts_as_taggable according to the examples in the Rails
Recipes book.  Everything works fine except for cases where I want to
use a tag with a dot (like .NET) or a slash (like COM/OLE).

The problem is not really with acts_as_taggable, but rather with
routing.

I am using the suggested technique where I use urls like /kb/list/
mytag to display all the entries tagged "mytag."

Here is the console output showing what happens when I use urls with
dots or slashes:

This works as expected:

>> rs.recognize_path "/kb/list/mytag"
=> {:id=>"mytag", :action=>"list", :controller=>"kb"}

But check these out:

>> rs.recognize_path "/kb/list/.NET"
=> {:anything=>["kb", "list",
".NET"], :controller=>"kb", :action=>"index"}

>> rs.recognize_path "/kb/list/COM%2FOLE"
=> {:anything=>["kb", "list", "COM",
"OLE"], :controller=>"kb", :action=>"index"
}

Note that I replaced "/" with "%2F" because that's what happens in the
browser when it urlencodes the string "COM/OLE."

I suppose I could re-write the "list" action to use numeric ids
instead of tag names, but I would hate to lose that functionality.

Does anybody know how to get routing to work under these circumstances?
Mark (Guest)
on 2007-06-29 21:37
Why don't you use the permalink_fu plugin? It converts all the special
characters you described in a pretty url format. So instead of COM/OLE
it would be com-ole, then you could easily find your inestances by doing
Model.find_by_permalink(params[:permalink)

--

Serengeti wrote:
> I am using acts_as_taggable according to the examples in the Rails
> Recipes book.  Everything works fine except for cases where I want to
> use a tag with a dot (like .NET) or a slash (like COM/OLE).
>
> The problem is not really with acts_as_taggable, but rather with
> routing.
>
> I am using the suggested technique where I use urls like /kb/list/
> mytag to display all the entries tagged "mytag."
>
> Here is the console output showing what happens when I use urls with
> dots or slashes:
>
> This works as expected:
>
>>> rs.recognize_path "/kb/list/mytag"
> => {:id=>"mytag", :action=>"list", :controller=>"kb"}
>
> But check these out:
>
>>> rs.recognize_path "/kb/list/.NET"
> => {:anything=>["kb", "list",
> ".NET"], :controller=>"kb", :action=>"index"}
>
>>> rs.recognize_path "/kb/list/COM%2FOLE"
> => {:anything=>["kb", "list", "COM",
> "OLE"], :controller=>"kb", :action=>"index"
> }
>
> Note that I replaced "/" with "%2F" because that's what happens in the
> browser when it urlencodes the string "COM/OLE."
>
> I suppose I could re-write the "list" action to use numeric ids
> instead of tag names, but I would hate to lose that functionality.
>
> Does anybody know how to get routing to work under these circumstances?
Serengeti (Guest)
on 2007-06-29 21:43
(Received via mailing list)
Thanks for the tip!  I'll give that a try.
Serengeti (Guest)
on 2007-06-29 23:18
(Received via mailing list)
I'm a little stuck.  Maybe you can help.

I am adding:

has_permalink :name

to the class definition for Tag.

When I do this I get an error:

C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1
.15.3/lib/active_record/base.rb:1235:in
`method_missing':NoMethodError: undefine
d method `has_permalink' for Tag:Class

I assume this means that the acts_as_taggable plugin is trying to load
its models before permalink_fu has been loaded.

I have tried adding:

require 'permalink_fu' to tag.rb, but that returns file not found
errors.  I have tried a few different ways of specifying the path to
the permalink_fu plugin but none work.

Is there another way to accomplish this?
This topic is locked and can not be replied to.