Rails使用错误的自定义命名路由

时间:2015-08-14 18:06:10

标签: ruby-on-rails ruby-on-rails-4 routes namespaces

我正在构建一个博客文章版本系统,用户可以在其中执行以下操作:

  1. 将草稿更改为已发布的帖子
  2. 存档已发布的
  3. 重新发布和存档帖子
  4. 邮政的状态设置在邮政和邮政的一栏中。状态可以是"草稿","活动","存档"

    现在,每当我点击"发布"或者"重新发布"它将页面标记为"已存档。"

    PostsController.rb

    def mark_published
      @post = Post.find(params[:id])
      @post.update(status: 'active')
      @post.save
      redirect_to confirmation_admin_post_path(@post.id), notice: 'post has been Published.'
    end
    
     def mark_archived
        @post = Post.find(params[:id])
        @post.status = 'archived'
        @post.save
        redirect_to confirmation_admin_post_path(id: @post.id), notice: 'post has been archived.'
     end
    

    show.html.slim

     .col-sm-6.col-md-2.col-lg-2
       = link_to 'PUBLISH ', mark_published_admin_post_path(@post), class: 'btn btn-success btn-block mb15 btn-lg '
     .col-sm-6.col-md-2.col-lg-2
       = link_to 'ARCHIVE ', mark_archived_admin_post_path(@post), class: 'btn btn-success btn-block mb15 btn-lg 
    

    '

    的routes.rb

    namespace :admin do
      resources :posts do
          member do
           get 'posts',  to: 'posts#mark_archived', as: :mark_archived
           get 'posts',  to: 'posts#mark_published', as: :mark_published
           get 'posts',  to: 'posts#confirmation', as: :confirmation
        end 
      end
    end
    

    更新:

    mark_archived_admin_post GET    /admin/posts/:id/posts(.:format)                admin/posts#mark_archived
     mark_published_admin_post GET    /admin/posts/:id/posts(.:format)                admin/posts#mark_published
     mark_archived_admin_post GET    /admin/posts/:id/posts(.:format)                admin/posts#mark_archived
     confirmation_admin_post GET    /admin/posts/:id/posts/confirmation(.:format)     admin/posts#confirmation
    

0 个答案:

没有答案