Reputation: 215
I have a problem with my code which could be found here: https://github.com/marcvanderpeet12/bloccitfinal
On app/views/_favorite.html.erb I included the following link: <%= link_to [post, Favorite.new], method: :post do %>
the method: :post should make it a post but if I run the relevant page (http://localhost:3000/posts/48/) and try to click the favorites button i still get this error
No route matches [GET] "/posts/48/favorites"
Thought im pretty sure my route are set up right Any thoughts what might go wrong here?
Upvotes: 0
Views: 62
Reputation: 1795
You need a route for action show in your favorites controller
In your routes.rb you have resources :favorites, only: [:create, :destroy]
which means you don't have a route to show the post that you just submitted. You need to do this :
`resources :favorites, only: [:create, :destroy, :show]
and create the show action in your favoritesController, then create a view that renders that action.
Upvotes: 1
Reputation: 101
Your favorites_controller.rb
is empty. You need to define your create
and destroy
actions.
For the create action, grab your post and create a favorite using your user
object.
favorite = current_user.favorites.build(post: @post)
Check and save it.
Your destroy action could be something like:
favorite = current_user.favorites.find(params[:id])
where :id
is the ID of a favorite
object.
Upvotes: 0