Possible to use dashes instead of underscores in rails?


#1

Hi all -

My boss is asking me if we can have dashes instead of underscores in the
URL for SEO reasons. Apparently google prefers “foo-bar” to “foo_bar”.
The former will be found when searching for just “foo”, but not the
latter.

So, I’m wondering if there is a way without changing any of my code
if I can tell rails to use dashes instead of underscores?

Any ideas?


#2

Philip H. wrote:

Hi all -

My boss is asking me if we can have dashes instead of underscores in the
URL for SEO reasons. Apparently google prefers “foo-bar” to “foo_bar”.
The former will be found when searching for just “foo”, but not the
latter.

So, I’m wondering if there is a way without changing any of my code
if I can tell rails to use dashes instead of underscores?

Any ideas?

Im a n00b but, maybe look into mapping it like this:
map.connect ‘foo-bar’, :controller => “foo_bar”


#3

edit
Im a n00b but, maybe look into mapping it like this:
map.connect ‘/foo-bar’, :controller => “foo_bar”


#4

edit
Im a n00b but, maybe look into mapping it like this:
map.connect ‘/foo-bar/:action’, :controller => “foo_bar”


#5

How would this affect say a link_to call in a view…

say

link_to “some place”, :controller => “does_this_need_underscores”,
:action
=> “act”

Would this then be mapped to the dash route?


#6

I think so but rendering I would test
Text
so map should fix. As for rendering that needs to be ran by a test


#7

Philip H. wrote:

Hi all -

My boss is asking me if we can have dashes instead of underscores in the
URL for SEO reasons. Apparently google prefers “foo-bar” to “foo_bar”.
The former will be found when searching for just “foo”, but not the
latter.

So, I’m wondering if there is a way without changing any of my code
if I can tell rails to use dashes instead of underscores?

Any ideas?

map.connect ‘foo-bar/:action/:id’,
:controller => ‘foo_bar’,
:action => nil,
:id => nil

url_for :controller => ‘foo_bar’
#=> /foo-bar

url_for :controller => ‘foo_bar’,
:action => ‘narf’
#=> /foo-bar/narf

url_for :controller => ‘foo_bar’,
:action => ‘show’,
:id => @foo.id

#=> /foo-bar/show/123

Setting the routing params to nil tell the router they are optional.