2016-12-11 1 views
0

Ich bekomme ein seltsames Routing, wenn auf Heroku, aber nicht lokal, und ich habe keine Ahnung, wie ich damit fortfahren soll. dies ist der Fehler:Heroku ActionController :: Routing Fehler

ActionController::RoutingError (No route matches [GET] "/authors/posts/this-is-just-a-test/publish"):

Routen:

new_author_session GET /authors/sign_in(.:format)    devise/sessions#new 
     author_session POST /authors/sign_in(.:format)    devise/sessions#create 
destroy_author_session DELETE /authors/sign_out(.:format)   devise/sessions#destroy 
     author_password POST /authors/password(.:format)   devise/passwords#create 
    new_author_password GET /authors/password/new(.:format)  devise/passwords#new 
    edit_author_password GET /authors/password/edit(.:format)  devise/passwords#edit 
         PATCH /authors/password(.:format)   devise/passwords#update 
         PUT /authors/password(.:format)   devise/passwords#update 
        root GET /         blog/posts#index 
      edit_author GET /author/:id/edit(.:format)    author#edit 
       author GET /author/:id(.:format)     author#show 
         PATCH /author/:id(.:format)     author#update 
         PUT /author/:id(.:format)     author#update 
    publish_authors_post PUT /authors/posts/:id/publish(.:format) authors/posts#publish 
unpublish_authors_post PUT /authors/posts/:id/unpublish(.:format) authors/posts#unpublish 
     authors_posts GET /authors/posts(.:format)    authors/posts#index 
         POST /authors/posts(.:format)    authors/posts#create 
     new_authors_post GET /authors/posts/new(.:format)   authors/posts#new 
    edit_authors_post GET /authors/posts/:id/edit(.:format)  authors/posts#edit 
      authors_post GET /authors/posts/:id(.:format)   authors/posts#show 
         PATCH /authors/posts/:id(.:format)   authors/posts#update 
         PUT /authors/posts/:id(.:format)   authors/posts#update 
         DELETE /authors/posts/:id(.:format)   authors/posts#destroy 
       about GET /about(.:format)      blog/pages#about 
       contact GET /contact(.:format)      blog/pages#contact 
       write GET /write(.:format)      blog/pages#write 
       posts GET /posts(.:format)      blog/posts#index 
        post GET /posts/:id(.:format)     blog/posts#show 

post.rb

class Post < ApplicationRecord 
    extend FriendlyId 
    friendly_id :title, use: :slugged 

    belongs_to :author 

    scope :most_recent, -> {order(published_at: :desc)} 
    scope :published, -> {where(published: true)} 

    def should_generate_new_friendly_id? 
     title_changed? 
    end 

    def published_date 
     "Published on #{created_at.strftime("%-b, %-d, %-Y")}" 
    end 

end 

routes.rb

devise_for :authors 
    root to: 'blog/posts#index' 

    resources :author, only: [:show, :edit, :update] 
    namespace :authors do 
    resources :posts do 
     put 'publish' => 'posts#publish', on: :member 
     put 'unpublish' => 'posts#unpublish', on: :member 
    end 
    end 


    scope module: 'blog' do 
     get 'about' => 'pages#about', as: :about 
     get 'contact' => 'pages#contact', as: :contact 
     get 'write' => 'pages#write', as: :write 
     get 'posts' => 'posts#index', as: :posts 
     get 'posts/:id' => 'posts#show', as: :post 
    end 

dieser post Nach hat es nicht zu beheben.

+0

Für diese Strecke ist für id suchen, aber es sieht likeyou einige senden Art von Slug, "publish_authors_post PUT /authors/posts/:id/publish(.:format)", gibt es etwas mit dieser Route, die Sie versuchen, anders zu machen? Etwas im Modell, um vielleicht eine benannte Route zu erstellen? Modell für Post-und Route-Datei wäre nützlich, um zu helfen –

+0

@ RockwellRice Post und Routen hinzugefügt. – DavidK

Antwort

0

Sie greifen jedoch auf publish_authors_post_path sendet eine GET-Anfrage, wenn es nach einer PUT-Anfrage sucht.

Wenn Sie link_to verwenden, können Sie verwenden:

link_to 'Publish', publish_authors_post_path, method: :put 

Oder wenn Sie ein Formular verwenden:

form_tag publish_authors_post_path(@post), method: :put 
+0

Das habe ich bereits für das '<% = link_to" Publish ", publish_authors_post_path (post), Methode:: put, Klasse:" btn btn-sm btn-success "%>' aber funktioniert nicht. – DavidK

+0

Haben Sie Schienen UJS aktiviert? @DavidK – codyeatworld

+0

ist es in meiner appilcation.js-Datei aufgeführt, ja? – DavidK