2010-02-04 80 views
0
#routes.rb 
map.connect '/articles/new', :controller => 'articles', :action => 'new' 
map.connect '/articles/:author_name', :controller => 'articles', :action => 'show' 
map.connect '/articles/:author_name/edit', :controller => 'articles', :action => 'edit' 

map.resources :articles, :comments 

当我到/ articles/test并单击delete时,它什么都不做。我猜我的自定义路线正在阻止它,我该如何解决它?在Rails中使用自定义路由时,销毁方法不起作用

谢谢

+0

你是如何设置测试路线的,你的'link_to' /'button_to'代码启动了删除看起来像什么? – 2010-02-04 17:11:56

+0

我正在使用什么脚手架。我不这么认为,那该死的路线。 – 2010-02-04 17:43:16

+0

从您发布的代码中,您没有/ articles/test路径。 – 2010-02-05 09:46:57

回答

0

我想你想重新考虑你在这里做什么。

我会依靠路径前缀而不是定义重叠路线:

map.resources :articles, :path_prefix => '/articles/:author_name', :name_prefix => 'article_' 

那还是看你是否能定义你的资源是这样的:

map.resources :articles, :belongs_to => :author 

我知道你可以做到这一点a:has_many,你会得到你想要的命名空间,但对belongs_to没有正面的评价。

0

我之所以这么做,是因为我无法运用参数。或者更具体地说,Rails不会找到它。

#Articles controller 
@article = Article.find_by_name(params[:name]) 

#Article model 
def to_param 
    name 
end def to_param 
name 

我环顾四周,他们都说要做到这一点,但它不会为我工作的某些原因。我收到Couldn't find Article with ID=test错误。