2

我正在尝试在 Rails 3 中写博客,所以我有帖子。我想为这样的帖子制作漂亮的路线:posts/year/month/day/post-title. 所以我覆盖了 to_parammodel/post.rbfriendly_id用于标题:

extend FriendlyId
friendly_id :title, :use => :slugged

def to_param
  "#{year}/#{month}/#{day}/#{title.parameterize}"
end

我将其添加到routes.rb

resources :posts do
  collection do
    match ":year/:month/:day/:id", :action => "show"
  end
  member do
    post 'comment'
    delete 'comment/:comment_id', :action => 'destroy_comment', :as => 'destroy_comment'
  end
end

show这个作品中:

<%= link_to image_tag("/images/edit_icon.png"),            
    { :controller => 'posts', :action => 'edit' }, :id => @post %>

index里面说

routing error:
No route matches {:action=>"edit", :controller=>"posts"}.

我是 Rails 的新手,我还没有设法找出导致此错误的原因。谁能帮我弄清楚我做错了什么?

4

0 回答 0