#route开发者_开发技巧s.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
When I got to /articles/test and click delete, it does nothing. I'm guessing my custom routes are preventing it, how do I solve it?
Thanks
I think you want to rethink what you are doing here.
I would rely on the path prefix instead of defining overlapping routes:
map.resources :articles, :path_prefix => '/articles/:author_name', :name_prefix => 'article_'
That or see if you can define your resource like this:
map.resources :articles, :belongs_to => :author
I know you can do that with a :has_many and you get the namespacing you want, but not positive about belongs_to.
The reason I was doing that was before I couldn't get to params to work. Or more specifically Rails won't find it.
#Articles controller
@article = Article.find_by_name(params[:name])
#Article model
def to_param
name
end def to_param
name
end
I looked around and they all say to do that, but it won't work for me for some reason. I get Couldn't find Article with ID=test
error.
精彩评论