I've never encountered this problem before. I'm getting this error.
No route matches [GET] "/recipes/1/like"
Here is my routes.rb:
Rails.application.routes.draw do
root 'pages#home'
get '/home', to: "pages#home"
resources :recipes do
member do
post 'like'
end
end
end
Here is my recipes_controller:
def like
@recipe = Recipe.create(params[:id])
Like.create(like: params[:like], chef: Chef.first, recipe: @recipe)
#flash message
flash[:success] = "Your selection was sucessful"
redirect_to :back
end
Here is my html.erb file:
<%= render 'shared/page_title', title: @recipe.name.titleize %>
<div class= "row">
<div class="col-md-4 pull-right center">
<%= gravator_for @recipe.chef, size: 200 %>
<p>
<h5>Brought to you by: <%= @recipe.chef.chefname.capitalize %></h5>
</p>
</div>
<div class= "col-xs-8 col-md-8">
<%= link_to "Edit this Recipe", edit_recipe_path(@recipe), class: "btn btn-success pull-right" %>
<h3><%= @recipe.summary.capitalize %></h3>
<div class="show_recipe">
<%= image_tag(@recipe.picture.url, size: "300x200", class: "recipe-image") if @recipe.picture? %>
</div>
<div class ="well recipe-description">
<p>
<strong> Steps:</strong>
</p>
<%= simple_format(@recipe.description) %>
<div class="pull-right">
<%= link_to like_recipe_path(@recipe, like: true), method: :post do %>
<i class="glyphicon glyphicon-thumbs-up"></i>
<% end %>     
<%= link_to like_recipe_path(@recipe, like: false), :method => :post do %>
<i class="glyphicon glyphicon-thumbs-down"></i>
<% end %>
</div>
</div>
</div>
</div>
<h5><%= link_to "Return to Recipes Listings", recipes_path, class: "btn btn-warning btn-small" %></h5>
I've explicitly added the HTTP POST request to my html.erb file
%= link_to like_recipe_path(@recipe, like: true), method: :post do %>
but rails is complaining that there is no GET route request, which I never created in my routes because I need a POST request for this particular section of the web app.
Rake routes:
Prefix Verb URI Pattern Controller#Action
root GET / pages#home
home GET /home(.:format) pages#home
like_recipe POST /recipes/:id/like(.:format) recipes#like
recipes GET /recipes(.:format) recipes#index
POST /recipes(.:format) recipes#create
new_recipe GET /recipes/new(.:format) recipes#new
edit_recipe GET /recipes/:id/edit(.:format) recipes#edit
recipe GET /recipes/:id(.:format) recipes#show
PATCH /recipes/:id(.:format) recipes#update
PUT /recipes/:id(.:format) recipes#update
DELETE /recipes/:id(.:format) recipes#destroy
I am honestly lost. It seems that everything is in its right place.
Rails version:
Rails 4.2.5
I've defined the action, created the like model, nested the route under recipes, and explicitly requested for a post HTTP request in the html.erb page.
Any ideas would be great!
Cheers!