I am using friendly_id for my Product model. Here's my routes :
resources :products, only: :show
scope '/dash' do
resources :products
end
Now when I go to the edit action, I used friendly ID to load the correct form. The edit form loads correctly. But when I submit it, it gives an error like this :
No route matches [PATCH] "/products/P011700714"
How can I fix this?
The form for tag :
<%= form_for( edit_product_path(@product) ) do |f| %>
Follow these steps,
Remove resources :products, only: :show
from your routes as that is what causing the problem, as you only need show
action without the scope I would recommend you to add this line instead of resources :products, only: :show
get '/products/:id', to: 'products#show'
Change your form_for
tag to
<%= form_for @product do |f| %>
Fetch the record using slug
def edit
@product = Product.where("slug=? or id=?", params[:id], params[:id]).first
# your code
end
Hope this helps!