Skip to content

Instantly share code, notes, and snippets.

@lhoBas
Created August 3, 2010 19:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lhoBas/506996 to your computer and use it in GitHub Desktop.
Save lhoBas/506996 to your computer and use it in GitHub Desktop.
Problem:
ActionController::RoutingError: No route matches {:action=>"destroy", :controller=>"users", :id=>#<User id: 1, first_name: "Demo", last_name: "User", email: "demo@example.com">}
from /usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/route_set.rb:398:in `generate'
from /usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/route_set.rb:450:in `generate'
from /usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/route_set.rb:478:in `url_for'
from /usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/url_for.rb:132:in `url_for'
from /usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/route_set.rb:195:in `user_url'
from /usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/polymorphic_routes.rb:114:in `send'
from /usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/polymorphic_routes.rb:114:in `polymorphic_url'
from /usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0.rc/lib/action_dispatch/routing/url_for.rb:134:in `url_for'
from (irb):1
class Project < ActiveRecord::Base
has_many :memberships
has_many :invites
validates :name, :presence => true
validates :description, :presence => true
attr_accessible :name, :description
has_friendly_id :permalink, :use_slug => true
def permalink
"#{description}:#{name}"
end
def normalize_friendly_id(string)
string
end
end
MyDevApp::Application.routes.draw do |map|
root :to => 'home#index'
resources :users
resources :projects, :only => [:new, :create]
get ':project_id' => 'projects#show', :constraints => { :project_id => /\w{3,24}\/\w{3,24}/ }, :as => 'project'
put ':project_id' => 'projects#update', :constraints => { :project_id => /\w{3,24}\/\w{3,24}/ }, :as => 'project'
delete ':project_id' => 'projects#destroy', :constraints => { :project_id => /\w{3,24}\/\w{3,24}/ }, :as => 'project'
get ':project_id/edit' => 'projects#edit', :constraints => { :project_id => /\w{3,24}\/\w{3,24}/ }, :as => 'edit_project'
scope ':project_id', :constraints => { :project_id => /\w{3,24}\/\w{3,24}/ }, :as => :project do
resources :memberships, :path => 'members'
resources :invites do
get :accept, :on => :member
get :deny, :on => :member
end
end
end
class User < ActiveRecord::Base
has_friendly_id :permalink, :use_slug => true
attr_accessible :first_name, :last_name
validates :first_name, :presence => true
validates :last_name, :presence => true
def permalink
"#{last_name}/#{first_name}"
end
def normalize_friendly_id(string)
string
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment