yretuta
yretuta

Reputation: 8091

Rails 3 "No Route Matches" error With Custom Named Route

I have this custom route in my routes.rb

match '/businesses/:permalink', :to => 'businesses#show', :as => :business_permalink
resources :businesses

And I have constructed a link like this:

<%= link_to business.name, business_permalink_path %>

However, whenever I visit the page with that link, I get this error:

No route matches {:controller=>"businesses", :action=>"show"}

I tried inverting the route order:

resources :businesses
match '/businesses/:permalink', :to => 'businesses#show', :as => :business_permalink

This does not work. It works if I change the link to this:

The show action exists and is defined in the file controllers/businesses_controller.rb.I want to create a custom URL using my permalink.

I am new in Rails and I know I am just missing something. What am I missing?

Upvotes: 1

Views: 419

Answers (2)

Surya
Surya

Reputation: 16002

Try this:

<%= link_to business.name, business_permalink_path(business.permalink) %>

Upvotes: 5

MexicanHacker
MexicanHacker

Reputation: 2685

Try this:

match '/businesses/:permalink' => 'businesses#show', :as => :business_permalink

More here: http://railscasts.com/episodes/203-routing-in-rails-3

Upvotes: -1

Related Questions