Reputation: 51
I am getting the following error an UPDATE to an existing post on the Blog app (Rails):
I changed author_posts_path
to author_post_path
when I was getting an error
No route matches [PATCH] "/posts/my-second-post"
Now, I'm getting a new error as follows:
ActionController::UrlGenerationError in Blog::Posts#index
Showing C:/Users/Royal and Carla/Desktop/testBlog3c/app/views/layouts/_navbar.html.erb where line #18 raised:
No route matches {:action=>"show", :controller=>"author/post"}, missing required keys: [:id]
views/layouts/_navbar.html.erb
16 </li>
17 <li class="nav-item">
18 <%= link_to 'My posts', author_post_path, class: "nav-link #
{yield(:author)}" %>
19 </li>
20 </ul>
21 </div>
ontrollers/author/posts_controller.rb
private
def set_post
@post = Post.friendly.find(params[:id])
end
def post_params
params.require(:post).permit(:title, :body, :description, :banner_image_url)
end
Upvotes: 0
Views: 287
Reputation: 7777
It seems to to be you not passing the post object id if your routes.rb
file looks like this
namespace :author do
resources :posts
end
then run the rake routes
then you will get output looks like this
author_posts GET /author/posts(.:format) author/posts#index
POST /author/posts(.:format) author/posts#create
new_author_post GET /author/posts/new(.:format) author/posts#new
edit_author_post GET /author/posts/:id/edit(.:format) author/posts#edit
author_post GET /author/posts/:id(.:format) author/posts#show
PATCH /author/posts/:id(.:format) author/posts#update
PUT /author/posts/:id(.:format) author/posts#update
DELETE /author/posts/:id(.:format) author/posts#destroy
See this
edit_author_post GET /author/posts/:id/edit(.:format) author/posts#edit
author_post GET /author/posts/:id(.:format) author/posts#show
PATCH /author/posts/:id(.:format) author/posts#update
PUT /author/posts/:id(.:format) author/posts#update
you need to :id
for edit
, update
& show
if need edit then your edit link looks like this
edit_author_post_path(post_object_id) # object_id is a post.id
then update form_tag
will looks like this
form_for [:author, @post] do |f|...
It should work, hope it will helps.
Upvotes: 0
Reputation: 1
you want to update post,first you need a edit view and in this view request update action. so I think you first step change link path to edit_author_post(@post)
Upvotes: 0