Acrux
Acrux

Reputation: 406

No route matches [PATCH] "/posts" - Scaffold

I used scaffold to build my Post model, controller, and views. I added simple_form, paperclip, friendly_id, and ckeditor. Everything works except for when I try to edit a post. When I try editing a post I get a "No route matches [PATCH]" error.

My rake routes:

posts GET    /posts(.:format)                            posts#index
      POST   /posts(.:format)                            posts#create
new_post GET    /posts/new(.:format)                        posts#new
edit_post GET    /posts/:id/edit(.:format)                   posts#edit
post GET    /posts/:id(.:format)                        posts#show
     PATCH  /posts/:id(.:format)                        posts#update
     PUT    /posts/:id(.:format)                        posts#update
     DELETE /posts/:id(.:format)                        posts#destroy

My edit view:

<%= simple_form_for @post, url: posts_path do |f| %>
  <%= f.error_notification %>

  <div class="form-inputs">
    <%= f.input :title %>
    <%= f.input :news_image, as: :file %>
     <%= f.input :body, :as => :ckeditor, input_html: {:ckeditor => {:toolbar => 'FULL'}}, class: "form-control" %>
  </div>

  <div class="form-actions">
    <%= f.button :submit %>
  </div>
<% end %>


<%= link_to 'Show', @post %> |
<%= link_to 'Back', posts_path %>

Any ideas as to why this is occurring and how I can fix it?

Upvotes: 0

Views: 245

Answers (1)

Graham Slick
Graham Slick

Reputation: 6870

You wrote in your form:

posts_path

It should be:

post_path(id: @post.id)

However, I don't even think you need to specify a path. Using :

<%= simple_form_for @post do |f| %>

Should be enough

Upvotes: 1

Related Questions